July 2018
Beginner
236 pages
5h 34m
English
As the name suggests, when() only executes the effect-function when a condition is met and automatically disposes the side-effect after that. Thus, when() is a one-time side-effect compared to autorun() and reaction(), which are long-running. The predicate function normally relies on some observables to do the conditional checks. If the observables change, the predicate function will be re-evaluated.
when() takes two arguments, which are as follows:
when(predicate-function, effect-function): disposer-functionpredicate-function: () => boolean, effect-function: ()=>{}
The predicate function is expected to return a Boolean value. When it becomes true, the effect function is executed, and the when() is automatically disposed. Note that ...
Read now
Unlock full access