Quick Tutorial
You can skip this part if you've already read the Github README.
Atom
Atoms are holders of state.
Atoms may have actions.
There's the .focus
method, which can be used as a selector/lens. xoid is based on immutable updates, so if you "surgically" set state of a focused branch, changes will propagate to the root.
Derived state
State can be derived from other atoms. This API was heavily inspired by Recoil.
Alternatively, .map
method can be used to quickly derive the state from a single atom.
Atoms are lazily evaluated. This means that the callback functions of
$sum
and$doubleAlpha
in this example won't execute until the first subscription to these atoms. This is a performance optimization.
Subscriptions
For subscriptions, subscribe
and watch
are used. They are the same, except watch
runs the callback immediately, while subscribe
waits for the first update after subscription.
All methods of a xoid atom are covered up to this point. This concludes the basic usage! ๐