Published
Edited
Apr 8, 2022
Also listed in…
Tips and Utilities
Insert cell
Insert cell
Surprise-Free State Management! Designed for React with functional components, but can also be used with other frameworks (or no framework at all.)
Insert cell
Statery = import('https://cdn.skypack.dev/statery@0.5.4?min')
Insert cell
store = Statery.makeStore({counter: 0})
Insert cell
increment = () =>
store.set((state) => ({
counter: state.counter + 1
}))
Insert cell
{

while (true) {
const counter = store.state.counter

const retVal = html`
<div> Counter: ${counter} </div>
<div> <button>Add</button> </div>
`
retVal.querySelector('button').addEventListener('click', ()=> {
increment();
} );
await Promises.delay(1000);
yield retVal;
}
}
Insert cell
html`<div>
Counter (old ) state subscribed <b class='cstate'>null</b>
</br>
New (upcoming) state <b class='nstate'></b>
</div>`
Insert cell
{
// ( changes, state )
const listener =( changes, {counter}) => {
console.log("Changes:", changes)
document.querySelector('.cstate').innerHTML = counter
document.querySelector('.nstate').innerHTML = changes.counter
}
store.subscribe(listener)
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more