effectCell property
Create a cell for observing side effects defined in this
cell.
The returned cell evaluates to the value of this cell while making the following guarantees:
-
The value of
this
cell is only referenced when it notifies its observers. -
The value of
this
cell is referenced at most once per value change notification.
This allows a side effect to be placed in the value computation function of this cell, since it is guaranteed that the side effect will only be run when triggered by the dependency cells, and will not be run more than necessary.
The result of the side effect can be observed by observing this cell.
NOTE: Accessing the value results in an UninitializeCellError
being
thrown until the first value change notification. This exception is also
thrown when value is accessed while this cell is inactive.
IMPORTANT: These guarantees hold if this cell only calls its computation function when its value is referenced. If this cell calls its computation function even when its value is not referenced, then these guarantees no longer hold.
It should also be noted that these guarantees hold only when interacting with this cell via the cell returned by this property.
Implementation
ValueCell<T> get effectCell => EffectCell(this);