Replies: 1 comment 5 replies
-
Stale emission - https://github.com/ngneat/elf/blob/master/packages/store/src/lib/stale.spec.ts |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I believe it's not an issue but I wanted to ask if you faced the same flow as I'll describe. I guess, I saw the same while using akita.
Here is a small reproduction:
https://stackblitz.com/edit/angular-ivy-bvaokh?file=src/app/app.component.ts
(you need to change two lines of code with each other(28 and 29) to get the right flow)
The problem is that depending on which query I subscribe to first, I can find a bug in getting a value of the query. If I subscribe to filters first then I'll get
loading
always asfalse
on the screen(even though actions in the store are fine). If I subscribe to loading first then I will see that theloading
property is changing totrue
and then tofalse
and it's the right flow. The reason why I'm not usingasync
pipe here is that it'll subscribe always after init sofilters
will be subscribed first and it's a wrong flow.As I understand, it's just because of how js works(I'll try to describe a flow). When we subscribe to filters and loading queries we write down callback that will be performed on store changes. Once the store is changed, in the call stack are put 2 our callbacks with the state that is in the store now(loading now is
false
). Because filters query is subscribed first its callback is performed first and inside it, we're updating the store propertyloading
and it's nowtrue
. So that, loading query subscription is triggered with the current store(loading now istrue
). Once this's done, the first callback of loading query subscription will be performed since it was waiting for filters query subscription callback(and all synchronous code that was performed inside this callback) to be done. This callback has the store state that was when we updated filters(loading isfalse
) and because of it our property loading has the valuefalse
.Overall, it's just how synchronous code and call stack work(If I get it right).
I wanted to ask you @NetanelBasal what you think about it. I don't know whether it can be handled by lib without breaking changes or not and we just need to pay attention to the order of subscriptions in cases when we have 2 queries from one store and in the one query subscription we update the store property which the second one relies on.
Beta Was this translation helpful? Give feedback.
All reactions