A reactor is an Observer managed by a Behavior. You install reactors using Behavior.reactTo
on the behavior that receives the event.
A reactor is similar to a normal handler installed with Observable.on. It provides several benefits over
installing an observer directly:
The behavior uninstalls reactor when the Endpoint is destroyed
If reactor is asynchronous, the behavior tracks the resulting promise. It provides error handling and
ensures the promise completes before Endpoint destruction
The behavior ensures reactors run serially even if they are asynchronous
Matter.js manages the context in which the reactor runs automatically, either joining the emitter's context or
creating a dedicated offline context
Matter.js ensures that reactor only registers with Observable once for a given Endpoint
You may optionally designate resources (including Behaviors) for locking prior to reaction
You should not use arrow functions for reactors as this will prevent you from accessing the Behavior in the correct
context.
If observable is a high-volume emitter, it would be better to implement synchronous or very fast asynchronous
reactors to avoid accumulating too many deferred reactions.
A reactor is an Observer managed by a Behavior. You install reactors using Behavior.reactTo on the behavior that receives the event.
A reactor is similar to a normal handler installed with Observable.on. It provides several benefits over installing an observer directly:
The behavior uninstalls reactor when the Endpoint is destroyed
If reactor is asynchronous, the behavior tracks the resulting promise. It provides error handling and ensures the promise completes before Endpoint destruction
The behavior ensures reactors run serially even if they are asynchronous
Matter.js manages the context in which the reactor runs automatically, either joining the emitter's context or creating a dedicated offline context
Matter.js ensures that reactor only registers with Observable once for a given Endpoint
You may optionally designate resources (including Behaviors) for locking prior to reaction
You should not use arrow functions for reactors as this will prevent you from accessing the Behavior in the correct context.
If observable is a high-volume emitter, it would be better to implement synchronous or very fast asynchronous reactors to avoid accumulating too many deferred reactions.