Show / Hide Table of Contents

Class Reaction

A reaction is an IDerivation implementation that always run and does not have observers itself.

Inheritance
System.Object
Reaction
Implements
IDerivation
IDependencyNode
IDisposable
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:

  1. 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.
  2. They are not observable themselves
  3. They will always run after any 'normal' derivations
  4. 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:

  1. after creating, the reaction should be started by calling runReaction or by scheduling it(see also autorun)
  2. the onInvalidate handler should somehow result in a call to this.track(someFunction)
  3. all observables accessed in someFunction will be observed by this reaction.
  4. 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.
  5. onInvalidate will be called, and we are back at step 1.

Properties

| Improve this Doc View Source

DependenciesState

Gets or sets the state of the dependencies of this IDerivation instance.

Declaration
public DerivationState DependenciesState { get; set; }
Property Value
Type Description
DerivationState
| Improve this Doc View Source

IsDisposed

Gets a value indicating whether this reaction is disposed.

Declaration
public bool IsDisposed { get; }
Property Value
Type Description
System.Boolean
| Improve this Doc View Source

IsTracing

Gets or sets the trace mode of this Derivation.

Declaration
public TraceMode IsTracing { get; set; }
Property Value
Type Description
TraceMode
| Improve this Doc View Source

Name

Gets the Name of the Atom instance.

Declaration
public string Name { get; }
Property Value
Type Description
System.String
| Improve this Doc View Source

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>
| Improve this Doc View Source

Observing

Gets a set of IObservable instances that are currently observed.

Declaration
public ISet<IObservable> Observing { get; }
Property Value
Type Description
ISet<IObservable>
| Improve this Doc View Source

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
| Improve this Doc View Source

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
| Improve this Doc View Source

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 Source

Dispose()

Disposes the reaction by clearing the observables it is observing.

Declaration
public void Dispose()
| Improve this Doc View Source

OnBecomeStale()

Propagates confirmation of a possible change to all observers of this Reaction for delayed computation.

Declaration
public void OnBecomeStale()
| Improve this Doc View Source

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.

Implements

IDerivation
IDependencyNode
IDisposable

Extension Methods

TraceExtensions.Trace<TObject, TMember>(TObject, Expression<Func<TObject, TMember>>, TraceMode)
ReactiveObjectTypeUtilExtensions.GetObservable(Object)
ReactiveObjectTypeUtilExtensions.GetObservable<TObject, TMember>(TObject, Expression<Func<TObject, TMember>>)
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX