Reactions are a special kind of derivations. Several things distinguishes them from normal reactive computations
They will always run, whether they are used by other computations or not.
This means that they are very suitable for triggering side effects like logging, updating the DOM and making network requests.
They are not observable themselves
They will always run after any 'normal' derivations
They are allowed to change the state and thereby triggering themselves again, as long as they make sure the state propagates to a stable state in a reasonable amount of iterations.
The state machine of a Reaction is as follows:
after creating, the reaction should be started by calling runReaction or by scheduling it (see also autorun)
the onInvalidate handler should somehow result in a call to this.track(someFunction)
all observables accessed in someFunction will be observed by this reaction.
as soon as some of the dependencies has changed the Reaction will be rescheduled for another run (after the current mutation or transaction). isScheduled will yield true once a dependency is stale and during this period
onInvalidate will be called, and we are back at step 1.
Reactions are a special kind of derivations. Several things distinguishes them from normal reactive computations
The state machine of a Reaction is as follows:
runReaction
or by scheduling it (see alsoautorun
)onInvalidate
handler should somehow result in a call tothis.track(someFunction)
someFunction
will be observed by this reaction.isScheduled
will yield true once a dependency is stale and during this periodonInvalidate
will be called, and we are back at step 1.