Search code examples
rxjsrxjs6rxjs-pipeable-operators

Is there a way to subscribe the same value all time without subscribe break?


I am subscribing a value from a reducer, where it will always true. when first time i subscribes it works. but next time it's not. from my research always the value is true if i change value to false then it works fine.

so subscribe expect the different value to observer or unsubscription. at present I do like this:

this.store.dispatch(new actionsMc.CheckConcurrencySuccess(false));
this.store.dispatch(new actionsMc.CheckConcurrency(true));

even though I required to pass true always i do above to subscribe my update. instead of this work around any other way is there is rxjs any one help me?

in subscription i tried with take once but it not working further. but looking for some other work around.

here is my subscription:

this.store.pipe(last(select(subscribe.newvalue))).subscribe(res => {
   console.log('new res', res);
}) 

but not works. as a simple how to subscribe and unsubscribe on each value received?


Solution

  • If I understood you correctly, you are saying that even though the data in the store is updated to "true", you are not not notified about it in your subscription. That is because store automatically compares the new and the previous values, and fires .next() only if the values are not equal.

    The simplest solution for you would be to wrap the boolean field in your store into an object (or array: [boolean] instead of boolean), so you would get notified every time it is updated.