Perform a chain of operations in response to store changes.
Optionally apply changes back to the store.
Optionally reverse the chain when data is read from a storage location.
npm install -D svelte-chainstore
<script>
import { chain } from 'svelte-chainstore';
let changeCounter = 0;
const name = chain((v) => v.toUpperCase())
.chain((v) => {
changeCounter++;
return v;
})
.sync()
.store('JOHN');
</script>
<!-- chain ensures name value is always uppercase and also counts the changes made -->
<input bind:value={$name} />
<br />This value changed {changeCounter} times.
Inspired by Dean Fogarty's Svelte Summit Fall 2021 presentation