Stores

A store is simply an object with a subscribe method that allows interested parties to be notified whenever the store value changes.

set is a method that takes one argument which is the value to be set. The store value gets set to the value of the argument if the store value is not already equal to it.

update is a method that takes one argument which is a callback. The callback takes the existing store value as its argument and returns the new value to be set to the store.

So you can use update if the next value should be dependent on the current value.

In a component you usually should not subscribe to stores manually.

Auto subscription

Untitled

Writable store → read and write abilities

Readable store → read only ability (https://svelte.dev/tutorial/readable-stores)

Derived → create a store based on the value from other stores

Untitled

Custom store

Untitled