Class Reaction
A reaction is an IDerivation implementation that always run and does not have observers itself.
Inheritance
Namespace: Cortex.Net.Core
Assembly: Cortex.Net.dll
Syntax
public sealed class Reaction : object, IDerivation, IDependencyNode, IDisposable
Remarks
Reactions are a special kind of derivations. Several things distinguishes them from normal reactive computations:
- They will always run, not like derivations that only run when unobserved. 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 alsoautorun
) - the
onInvalidate
handler should somehow result in a call tothis.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.
Properties
| Improve this Doc View SourceDependenciesState
Gets or sets the state of the dependencies of this IDerivation instance.
Declaration
public DerivationState DependenciesState { get; set; }
Property Value
Type | Description |
---|---|
DerivationState |
IsDisposed
Gets a value indicating whether this reaction is disposed.
Declaration
public bool IsDisposed { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsTracing
Gets or sets the trace mode of this Derivation.
Declaration
public TraceMode IsTracing { get; set; }
Property Value
Type | Description |
---|---|
TraceMode |
Name
Gets the Name of the Atom instance.
Declaration
public string Name { get; }
Property Value
Type | Description |
---|---|
System.String |
NewObserving
Gets a set of IObservable instances that have been hit during a new derivation run.
Declaration
public ISet<IObservable> NewObserving { get; }
Property Value
Type | Description |
---|---|
ISet<IObservable> |
Observing
Gets a set of IObservable instances that are currently observed.
Declaration
public ISet<IObservable> Observing { get; }
Property Value
Type | Description |
---|---|
ISet<IObservable> |
RequiresObservable
Gets a value indicating whether to warn if this derivation is required to visit at least one observable.
Declaration
public bool RequiresObservable { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
RunId
Gets or sets the id of the current run of a derivation. Each time the derivation is tracked this number is increased by one. This number is unique within the current shared state.
Declaration
public int RunId { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
SharedState
Gets the Shared State of all the nodes in the dependency graph.
Declaration
public ISharedState SharedState { get; }
Property Value
Type | Description |
---|---|
ISharedState |
Methods
| Improve this Doc View SourceDispose()
Disposes the reaction by clearing the observables it is observing.
Declaration
public void Dispose()
OnBecomeStale()
Propagates confirmation of a possible change to all observers of this Reaction for delayed computation.
Declaration
public void OnBecomeStale()
Track(Action)
Tracks this reaction using the specified action.
Declaration
public void Track(Action action)
Parameters
Type | Name | Description |
---|---|---|
Action | action | The action to use to track. |