-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Expose additional implementation details for stores #6667
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
Is couple of excessive updates really that big of a deal that you can't use svelte though? |
I'm really wary about adding anything to the official store contract, and I'm also wary about adding anything to the public APIs for the store implementations that isn't part of the contract. |
The svelte implementation solves the diamond dependency issue by sending signals breadth first. It does this by queuing signals in an internal list. const run_queue = !subscriber_queue.length;
for (const subscriber of subscribers) {
subscriber[1]();
subscriber_queue.push(subscriber, value);
}
if (run_queue) {
for (let i = 0; i < subscriber_queue.length; i += 2) {
subscriber_queue[i][0](subscriber_queue[i + 1]);
}
subscriber_queue.length = 0;
} Given that |
Any changes would need to be 100% backwards compatible and fall in line with the existing design.
Each of the above should carry very little risk. |
Yeah i get that. I don't get what real world problem you can't solve with the current setup. Your sample just demonstrates order of internal updates, and isn't anything useful to the end user. |
The sample demonstrates that if I use a 3rd party store for some stores, then derived stores will emit incorrect signals. |
I apologize if I am being obtuse. If it's the former, I've made a clearer example of the issue: As you can see, when not using the built-in store, the derived store gets prematurely evaluated with a mix of old and new data. |
I'm also running into this issue when implementing a store that syncs across multiple window contexts using the Channel Messaging API. |
If it's of use, I've written a rather comprehensive replacement for the default store implementations stores-mono. If you are after a drop-in replacement, try @crikey/stores-svelte. As suggested by this ticket though, you'll need to ensure that all stores use this or similar replacement to solve the issue. I hope this helps. |
Thanks @WHenderson that is really helpful! |
Closing as won't do since with Svelte 5, runes are the primary mechanism for universal reactivity which are superior with regards to fine grained reactivity and firing at the right times |
Uh oh!
There was an error while loading. Please reload this page.
Describe the problem
The svelte store paradigm currently uses a breadth-first signaling pattern to solve the "diamond dependency problem".
This is a good solution, but the internal queue (subscriber_queue) is a hidden internal variable and this means that when writing a new store implementation, there will be issues with interoperability.
i.e. the signaling will no longer be perfectly "breadth first" and thus issues like the diamond dependency will be intractable when mixing store types.
See this REPL for an illustration of the problem
https://svelte.dev/repl/b9506f52bba44c158d4cddf996252ee0?version=3.42.1
Describe the proposed solution
I would recommend the internal signal queue (subscriber_queue) be exposed as a small API.
Internally the queue could be represented as an array of actions, allowing broader extensibility.
Notably svelte-immer-store internally signals with more than just new_value, and a queue of actions would allow authors to adopt their own requirements.
I would be happy to develop and submit a pull request to solve this issue. But I would like guidance to make sure the effort was not wasted.
Alternatives considered
The only other alternative I can find is to avoid mixing the stores, but that means no interoperability between libraries.
Importance
i cannot use svelte stores without it
Edit: should have said i cant use svelte stores. Svte itself is still good 😅
The text was updated successfully, but these errors were encountered: