You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A store may optionally contain a .set method, which [...] synchronously calls all of the store’s active subscription functions.
This is not the behavior I observe from Svelte's built-in stores, as they seem to schedule the calls to the subscriptions till after the calling function is done. I understand that this behavior is probably intended, my main concern is with the documentation.
It would be very helpful to have a proper documentation of how Svelte's stores actually behave.
You might be confusing synchronously with immediately or instantly. I think what you're seeing is Svelte waiting for the current subscribe to finish before triggering the next subscribers.
Edit: synchronous means that this will always work:
<script>
import { writable } from'svelte/store'let store =writable('foo');let value;constunsub=store.subscribe(v=> { value = v; });store.set('bar');unsub();console.log(value);
</script>
Describe the bug
In https://svelte.dev/docs/svelte/stores#Store-contract the documentations states:
This is not the behavior I observe from Svelte's built-in stores, as they seem to schedule the calls to the subscriptions till after the calling function is done. I understand that this behavior is probably intended, my main concern is with the documentation.
It would be very helpful to have a proper documentation of how Svelte's stores actually behave.
Reproduction
Consider the following example:
Which (after clicking the button) results in the output:
As you can see, the
.set
method finishes and the surrounding code is executed before the subscriptions are called.Logs
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: