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 atemno

Live, 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.

price: freshprice12heldquantity: freshquantity2heldcoupon: freshcouponfalseheldsubtotal: freshsubtotal24×1discount: freshdiscount0×1total: freshtotal24×1label: freshlabel"$24"×1observed
  • fresh
  • dirty
  • maybe stale
  • never read
  • released
price
12
quantity
2
coupon
observe label

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.

Code
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');
Output
double is 0
double is 6
it ran 2 times

Coming from Jotai or Recoil?

The atoms will look familiar. Where the state lives, how atoms are named, and when it is let go will not. Here is what changes, and when the others are the better pick.

Read the comparison

Describe your state. Let a domain hold it.

Start with the quick start, or poke at the graphs in the explorer.