-1

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?

3gwebtrain
  • 14,640
  • 25
  • 121
  • 247

1 Answers1

2

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.

D Pro
  • 1,756
  • 1
  • 8
  • 15
  • @D Pro such this : obj = { required : true } - so always the `obj` update will available with `required` ? – 3gwebtrain Sep 19 '19 at 05:39
  • yes, whenever you assign a new value to object, store will push a new value to the subscriber. But also have a look in your selector: if it's resulting value is boolean, it still will not work, it needs to return an object or array – D Pro Sep 19 '19 at 05:42