svelte-ux
Version:
- Increment version in `package.json` and commit as `Version bump to x.y.z` - `npm run publish`
29 lines (28 loc) • 824 B
JavaScript
import { writable } from 'svelte/store';
/**
* Store to manage unique values using `Set` (with improves ergonomics and better control of updates)
*/
export default function uniqueStore(initialValues) {
const store = writable(new Set(initialValues !== null && initialValues !== void 0 ? initialValues : []));
return {
...store,
add(value) {
store.update((set) => {
set.add(value);
return set;
});
},
addEach(values) {
store.update((set) => {
values.forEach((value) => set.add(value));
return set;
});
},
delete(value) {
store.update((set) => {
set.delete(value);
return set;
});
},
};
}