Closed
Description
Description
Every now and then I forget how to properly use the "callback on subscriber" form of the built-in svelte stores, and end up writing something like this:
const store = writable(false, () => api.getData());
which doesn't work, because it should actually be written like this:
const store = writable(false, (set) => set(api.getData()));
A rule that ensures any readable
or writable
stores that use the callback form follow these rules would be great:
- Callback must accept a single parameter
- Somewhere within the callback function body it should execute that parameter as a function
I don't think we can get too much more descriptive about it, but even just those two checks would save me from debugging my bad stores.