Skip to content
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

[suggestion] talk about mutation in a writable store that is an object #458

Open
ZYinMD opened this issue Apr 7, 2023 · 0 comments
Open

Comments

@ZYinMD
Copy link

ZYinMD commented Apr 7, 2023

I was learning svelte by reading the interactive tutorial from start to finish. When I got to the readable store part, having used redux, I immediately think:

  1. Nice, I can use writable stores as mini redux stores.
  2. Can I mutate it? like this:
const myStore = writable({ foo: 1 });

myStore.update((prev) => {
  prev.foo = 2;
  return prev;
});

The answer is yes, and that's a HUGE deal, because you can't do it in redux, and that has been drilled to people's heads.

In the current tutorial here and here, the example store is an integer:

export const count = writable(0);

And my initial assumption was "I probably can't do mutate in a store, otherwise the doc wouldn't have used an integer to demo it". Many many others may think like me - being able to mutate feels too good to be true.

So, I suggest adding a demo of an object as writable store. You have no idea how much redux has changed people brain.

(side note: even chatGPT is affected by redux, try asking I have a svelte writable store that is an object, how do I update a slice of it? and see what it says)

@ZYinMD ZYinMD changed the title [suggestion] talking about mutation in a writable store that is an object [suggestion] talk about mutation in a writable store that is an object Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant