svelte-ux
Version:
- Increment version in `package.json` and commit as `Version bump to x.y.z` - `npm run publish`
17 lines (16 loc) • 434 B
JavaScript
import { derived } from 'svelte/store';
function changeStore(store, onChange) {
let previous = undefined;
return derived(store, ($store) => {
const value = { previous, current: $store };
if (previous === undefined) {
// First update
}
else if (onChange) {
onChange(value);
}
previous = $store;
return value;
});
}
export default changeStore;