A framework agnostic core, with React bindings
State that recomputes only what you read.
Atoms and computeds describe values. A domain stores them and records what each computed reads. A write only marks what depends on it, and a computed reruns when something reads it.
$ npm install atemnoLive, not a diagram
Write an atom. Watch what reruns.
This is a real domain. Change the price and everything label depends on runs at once, because it is observed. Switch that off, read label once, and change the price again: now nodes go stale and wait for someone to ask.
- fresh
- dirty
- maybe stale
- never read
- released
Events
Change something to see what runs.
Examples and their output
Each tab shows a short program and what it printed when run with atemno.
A computed nobody reads does no work. Three writes, one rerun.
import { atom, computed, ReactiveDomain } from 'atemno';
const count = atom('count', 0);
let runs = 0;
const double = computed('double', $ => {
runs++;
return $.get(count) * 2;
});
const domain = new ReactiveDomain({});
console.log('double is', domain.get(double));
domain.set(count, 1);
domain.set(count, 2);
domain.set(count, 3);
console.log('double is', domain.get(double));
console.log('it ran', runs, 'times');double is 0
double is 6
it ran 2 timesDescriptions, not state
An atom holds nothing. A ReactiveDomain holds the values, so the same atom carries different state in every domain.
Lazy by default
Writing marks what depends on it stale. A computed reruns when something reads it, and not before.
Equal values stop early
A computed that returns an equal result ends the update there. Nothing downstream of it runs.
Dependencies per run
A computed depends on what it read last time, so a branch it did not take is not a dependency.
Released when unused
A node goes away once nothing tracks it, so keyed state does not pile up behind you.
Framework agnostic
The core has no framework in it. React ships as a binding, and anything else is one subscription.
Describe your state. Let a domain hold it.
Start with the quick start, or poke at the graphs in the explorer.