Race condition on updating store in store.select(...) subscription #695
Replies: 4 comments 2 replies
-
Thank you @shanovskyi-b for submitting this. It's really sad to be unable to update a property like that. I've made some research on the issue and found out this behavior can be reproduced with pure RxJS, using a BehaviorSubject instead of Akita Store. So it seems to be an RxJS bug, still reproduced with latest v7.1.0. Nevertheless it may be worth trying to implement a workaround in Akita, because state properties depending on each other seem to be a very common solution. I would gladly work on a PR, but I'm not sure what is the best approach here. Really need to know most active contributors' opinion! |
Beta Was this translation helpful? Give feedback.
-
Hey @staciedev, thanks for your response. Could you add a bit more info about the RxJs bug you have mentioned? (probably there's some rxjs github issue or just some minimal reproduction) I've tried to play around updating the BehaviourSubject values in it's own subscription (which is probably happening in the Akita store), but wasn't able to reproduce it |
Beta Was this translation helpful? Give feedback.
-
@shanovskyi-b |
Beta Was this translation helpful? Give feedback.
-
There are similar closed issues where I described that it's not related to Akita. As @staciedev said, it's how Rx works. |
Beta Was this translation helpful? Give feedback.
-
I'm submitting a...
Current behavior
When you subscribe via
store.select
toprop1
and usestore.update
forprop2
in theprop1
subscription it revertsprop2
state.Expected behavior
Store update works fine in the
store.select
subscription.Minimal reproduction of the problem with instructions
STEPS TO REPRODUCE:
store.update
for the second property in it;What happens:
prop1
update is called ✔️prop1
subscribe is called that callsprop2
update ✔️prop2
subscribe is called with newprop2
value ✔️prop2
subscribe is called again with previousprop2
value (the one that was before new) 🟥MINIMAL DEMO:
https://stackblitz.com/edit/akita-todos-app-y1bwtu?file=src/app/test/test.component.ts
What is the motivation / use case for changing the behavior?
It's quite common to make some data loading based on some UI filter's state, the easiest way to do that is in the subscription to filter's state property.
Inside of this subscription it's quite useful to set a loading flag, clean up the existing data and finally make call for the new data.
Because of the bug, the loading flag is not set, the data is not cleaned.
The workaround is to use
setTimeout
in the subscription but i believe it shouldn't work like that,Environment
Beta Was this translation helpful? Give feedback.
All reactions