UNPKG

svelte-ux

Version:

- Increment version in `package.json` and commit as `Version bump to x.y.z` - `npm run publish`

37 lines (36 loc) 938 B
import { writable } from 'svelte/store'; /** * Store to wrap `Map` to simplify syncing state (set, delete, clear) with Svelte */ export default function mapStore(initialValues) { const store = writable(new Map(initialValues)); return { subscribe: store.subscribe, set(key, value) { store.update((map) => { map.set(key, value); return map; }); }, delete(key) { store.update((map) => { map.delete(key); return map; }); }, clear() { store.update((map) => { map.clear(); return map; }); }, /** * Force a reactive update in case of internal changes to entries */ refresh() { store.update((map) => { return map; }); }, }; }