A value or data structure which cannot be mutated
Registers a function to be run each time the state of atom
changes.
Will throw an Error if key
is already taken by another handler.
Dereferences (i.e. "reads") the current state of an Atom. The dereferenced value should not be mutated.
the type of atom
's inner state
Deletes the key
and the handler associated with key
so that it not longer runs
when the state of atom
changes.
Sets the validator
for atom
. validator
must be a pure function of one argument,
which will be passed the intended new state on any state change. If the new state is
unacceptable, validator
should return false or throw an exception. If the current state
is not acceptable to the new validator, an exception will be thrown and the validator will
not be changed.
the type of atom
's inner state
Swaps atom
's state with the value returned from applying updateFn
to atom
's
current state. updateFn
should be a pure function and not mutate state
.
the type of atom
's inner state
an instance of Atom
a pure function that takes the current state and returns the next state; the next state should be of the same type/interface as the current state;
Extracts the type info of an Atom's inner state
const state = Atom.of({count: 0}); const increment = (s: AtomState<typeof state>) => ({ count: s.count + 1 }) swap(state, increment);