-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Stores not honoring contract described in the documentation #15984
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
You might be confusing synchronously with immediately or instantly. I think what you're seeing is Svelte waiting for the current Edit: synchronous means that this will always work: <script>
import { writable } from 'svelte/store'
let store = writable('foo');
let value;
const unsub = store.subscribe(v => {
value = v;
});
store.set('bar');
unsub();
console.log(value);
</script> Edit2: I think this makes it absolutely clear what synchronous means: <button on:click={() => {
select.set(++i);
console.log('after set');
}}>assign</button> |
My issue is not the word "synchronously". Just ignore the word:
For me what it means when a method calls a function is that the call is inside that method. Otherwise it should be something like "which ensures that the subscribe functions are called (synchronously) in the future". I showed this sentence to several colleagues and everyone understood it that way. Please do me a favor and honestly ask yourself, if you had no idea how svelte works, would you expect the first method to finish before calling the second one after reading that sentence from the documentation? |
In a case like your one, you expect the execution order of subscribers be
but it is
It was introduced in #3219 for a reason. You can always open a PR to the docs. There is even a button for this in the docs. |
Ok, look, I'm not a front end developer and I don't regularly use Svelte. I just had to fix something for a random task, came to your docs for information and found something that was (in my view) wrong or at least misleading, so I thought I'd tell you. Do with that what you want, feel free to close this issue. I'm not going to fix your docs because I'm neither qualified nor willing to do so, especially since none of you seem to care about the state of your documentation anyways. |
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: