Custom Store Pattern with subscribe/set/update
Build a store with encapsulated logic by exposing a subscribe method and custom actions.
Store Contract
Any object with a subscribe(fn) method that returns an unsubscribe function is a valid Svelte store.
Wrap a writable
Build a custom store by wrapping a writable and exposing a focused API.
function createCounter() {
const { subscribe, set, update } = writable(0);
return {
subscribe,
increment: () => update(n => n + 1),
reset: () => set(0)
};
}All lessons in this course
- derived() for Computed Stores
- Custom Store Pattern with subscribe/set/update
- Readable from Writable
- Store Contracts and Interoperability