-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Observer still called when unsubscribed during store update #4794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
One concern with changing this is that it potentially relies on the observers being called in the same order in which they were subscribed. For example, if in the future stores are changed so that the callbacks are called in reverse order of subscription, the behavior of the example above would change so that both callbacks are called once again. With that in mind, I think I would feel most comfortable with this change if Svelte made one of these behaviors official:
or
What do you think? |
Observables are just arrays of callbacks so as per ECMA the order is guaranteed, I don't see how that could change in the future |
The most obvious possibility in my mind is that at some point in the future there is a need for better performance of unsubscribing, and so the array of subscribers is replaced with some other data structure. It would probably be a Map though, and so iteration would still be in insertion order. I suppose some other change could necessitate iterating in reverse order, but I cant think of any real reason to do that. But mostly I'm just thinking about the formal promises made by the Svelte API vs. the logical, but undocumented behavior that it exhibits, such as iterating over subscribers in the order they were added. If the answer is that I'm just worrying too much, that's fine and I'm happy to drop the issue :) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
https://svelte.dev/repl/703dd3e1045543388fd5583c489bac55?version=3.22.2
will fix with #4742 unless someone thinks this behavior is expected ?
The text was updated successfully, but these errors were encountered: