user2024080
user2024080

Reputation: 5101

RxJs - Not updating the `Observable` prints allwasy same result

In RxJx I am trying to update the 'Observable` But it not updating the value. I am keep getting the first declared values.

how to fix this?

here is my code :

 const streamA$ = Rx.Observable.of(2);
  const streamB$ = Rx.Observable.of(4);

 streamA$ = Rx.Observable.of(10) //not updating!

  const streamC$ = Rx.Observable.concat(streamA$, streamB$)
  .reduce((x, y) => x  + y);



streamC$.subscribe(function(x){
  console.log( x );
}); //prints 6

//even from here i would like to update
    streamA$ = Rx.Observable.of(10) //not updating!

Upvotes: 0

Views: 64

Answers (1)

Matt Burnell
Matt Burnell

Reputation: 2796

You've declared streamA$ using const, and you subsequently attempt to reassign it. Doing this will cause the original value to be retained. If you want to reassign streamA$, you'll need to declare it using var. This is true of all javascript variables, and isn't peculiar to Rx.

I suspect what you actually want to do here is either combine streamA$ with another stream, or feed a value directly into streamA$ (in which case you'll need it to be a Subject of some kind).

Upvotes: 1

Related Questions