Class: Reaction
Defined in: mobx:
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
runReactionor by scheduling it (see alsoautorun) - the
onInvalidatehandler should somehow result in a call tothis.track(someFunction) - all observables accessed in
someFunctionwill 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).
isScheduledwill yield true once a dependency is stale and during this period onInvalidatewill be called, and we are back at step 1.
Implements
IDerivationIReactionPublic
Accessors
diffValue
Get Signature
get diffValue(): 0 | 1;Defined in: mobx:
Returns
0 | 1
Set Signature
set diffValue(newValue: 0 | 1): void;Defined in: mobx:
Parameters
| Parameter | Type |
|---|---|
newValue | 0 | 1 |
Returns
void
isDisposed
Get Signature
get isDisposed(): boolean;Defined in: mobx:
Returns
boolean
Set Signature
set isDisposed(newValue: boolean): void;Defined in: mobx:
Parameters
| Parameter | Type |
|---|---|
newValue | boolean |
Returns
void
isRunning
Get Signature
get isRunning(): boolean;Defined in: mobx:
Returns
boolean
Set Signature
set isRunning(newValue: boolean): void;Defined in: mobx:
Parameters
| Parameter | Type |
|---|---|
newValue | boolean |
Returns
void
isScheduled
Get Signature
get isScheduled(): boolean;Defined in: mobx:
Returns
boolean
Set Signature
set isScheduled(newValue: boolean): void;Defined in: mobx:
Parameters
| Parameter | Type |
|---|---|
newValue | boolean |
Returns
void
isTrackPending
Get Signature
get isTrackPending(): boolean;Defined in: mobx:
Returns
boolean
Set Signature
set isTrackPending(newValue: boolean): void;Defined in: mobx:
Parameters
| Parameter | Type |
|---|---|
newValue | boolean |
Returns
void
Constructors
Constructor
new Reaction(
name_: string | undefined,
onInvalidate_: () => void,
errorHandler_?: (error: any, derivation: IDerivation) => void,
requiresObservable_?: any): Reaction;Defined in: mobx:
Parameters
| Parameter | Type |
|---|---|
name_ | string | undefined |
onInvalidate_ | () => void |
errorHandler_? | (error: any, derivation: IDerivation) => void |
requiresObservable_? | any |
Returns
Reaction
Methods
dispose()
dispose(): void;Defined in: mobx:
Returns
void
Implementation of
getDisposer_()
getDisposer_(abortSignal?: GenericAbortSignal): IReactionDisposer;Defined in: mobx:
Parameters
| Parameter | Type |
|---|---|
abortSignal? | GenericAbortSignal |
Returns
onBecomeStale_()
onBecomeStale_(): void;Defined in: mobx:
Returns
void
Implementation of
IDerivation.onBecomeStale_reportExceptionInDerivation_()
reportExceptionInDerivation_(error: any): void;Defined in: mobx:
Parameters
| Parameter | Type |
|---|---|
error | any |
Returns
void
runReaction_()
runReaction_(): void;Defined in: mobx:
internal, use schedule() if you intend to kick off a reaction
Returns
void
schedule_()
schedule_(): void;Defined in: mobx:
Returns
void
toString()
toString(): string;Defined in: mobx:
Returns a string representation of an object.
Returns
string
trace()
trace(enterBreakPoint?: boolean): void;Defined in: mobx:
Parameters
| Parameter | Type |
|---|---|
enterBreakPoint? | boolean |
Returns
void
Implementation of
track()
track(fn: () => void): void;Defined in: mobx:
Parameters
| Parameter | Type |
|---|---|
fn | () => void |
Returns
void
Properties
dependenciesState_
dependenciesState_: IDerivationState_;Defined in: mobx:
Implementation of
IDerivation.dependenciesState_isTracing_
isTracing_: TraceMode;Defined in: mobx:
Implementation of
IDerivation.isTracing_name_
name_: string;Defined in: mobx:
Implementation of
IDerivation.name_newObserving_
newObserving_: IObservable[];Defined in: mobx:
Implementation of
IDerivation.newObserving_observing_
observing_: IObservable[];Defined in: mobx:
Implementation of
IDerivation.observing_requiresObservable_?
optional requiresObservable_?: any;Defined in: mobx:
warn if the derivation has no dependencies after creation/update
Implementation of
IDerivation.requiresObservable_runId_
runId_: number;Defined in: mobx:
Id of the current run of a derivation. Each time the derivation is tracked this number is increased by one. This number is globally unique
Implementation of
IDerivation.runId_unboundDepsCount_
unboundDepsCount_: number;Defined in: mobx:
amount of dependencies used by the derivation in this run, which has not been bound yet.
Implementation of
IDerivation.unboundDepsCount_