File size: 570 Bytes
bc20498 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import { withGet } from './withGet.js';
export const overridable = (_store, onChange) => {
const store = withGet(_store);
const update = (updater, sideEffect) => {
store.update((curr) => {
const next = updater(curr);
let res = next;
if (onChange) {
res = onChange({ curr, next });
}
sideEffect?.(res);
return res;
});
};
const set = (curr) => {
update(() => curr);
};
return {
...store,
update,
set,
};
};
|