Search
Loading...
Skip to content

Interface: Reaction

Reactions track read calls and provide a way to react if they change.

  • Read calls are tracked by passing a function to track. That function will be executed, and any read calls made during that execution will be tracked and associated with this reaction.
  • Reactions can be subscribed to by passing a callback to subscribe. That callback will be executed whenever any of the read calls associated with this reaction change.

Methods#

track()#

track<T>(cb): T;

Execute the callback and track all engine read calls that happen during the execution. These read calls are associated with this reaction.

Type Parameters#

Type Parameter
T

Parameters#

ParameterType
cb() => T

Returns#

T


subscribe()#

subscribe(cb): () => void;

When the Reactor detects that the engine read calls associated with this reaction might have changed, it will invoke the subscription handler.

Parameters#

ParameterType
cb() => void

Returns#

A function that can be called to unsubscribe the handler.

(): void;
Returns#

void


dispose()#

dispose(): void;

Unsubscribe all handlers, nullify the reference to the Reactor and dispose the reaction.

Returns#

void