Advanced concepts
Deriving state from external sources
With an additional feature of get
function, you can get the state from non-atoms. This can be a Redux store, an RxJS observable, or anything that implements getState & subscribe pair. Here is an atom that derives its state from a Redux store.
Enhanced atoms
An enhanced atom is an atom whose default .set
method is swapped with something else. This technique can be used to create "pass through atoms" that act as a mediators. Most people using xoid will not need to write enhanced atoms.
Swapping
.set
also affects.update
, because it uses.set
internally. This is an intentional feature.
Streams
With no arguments used, create
function produces a special atom called a Stream
.
Stream
s are almost identical to atoms. In xoid world, there are two ways to create a stream:
- Atoms that start off with zero arguments like above.
- Filtering via
.map
method +true
as the second argument.
Here's the difference of the two, from the index.d.ts
file of xoid.
Observe that the few major differences are the
.value
getter and bunch ofprevState
s.