svelte-dnd-action
Version:
*An awesome drag and drop library for Svelte 3 and 4 (not using the browser's built-in dnd, thanks god): Rich animations, nested containers, touch support and more *
19 lines (18 loc) • 419 B
JavaScript
export function createStore(initialValue) {
let _val = initialValue;
const subs = new Set();
return {
get: () => _val,
set: newVal => {
_val = newVal;
Array.from(subs).forEach(cb => cb(_val));
},
subscribe: cb => {
subs.add(cb);
cb(_val);
},
unsubscribe: cb => {
subs.delete(cb);
}
};
}