Function: reuseComposedState()
API / @xmachines/play-actor / reuseComposedState
function reuseComposedState(prev, next): PlaySpec | null;Defined in: packages/play-actor/src/context-projection.ts:92
Reuses the composed state of the previous emission, or the complete previous
spec, when the value of the projection did not change.
deriveCurrentView composes state: { ...meta.view.state, context: slice } new
on each call, and the XState function assign makes a new context object on
every event. Without this reuse, every event therefore presents a new state
reference, and the Object.is test of each field in the emit gate emits the view
again and remounts it, without an end. The function compares the slices field by
field (shallowEqualExcept), because the XState function assign makes a
new context object for each event, and a test of the identity of the whole object
therefore reports a change every time. The authored fields come from the static
meta.view.state through a spread. Therefore their references are stable for an
unchanged viewKey, and a plain Object.is test is correct for them.
The function returns one of three values, in this order of preference:
previtself, when nothing observable changed. The emit gate then stops at the identity of the reference, and it walks no element;{ ...next, state: prev.state }, when the value of the state did not change but another top-level field is different;next, when something changed.
Parameters
| Parameter | Type |
|---|---|
prev | PlaySpec | null |
next | PlaySpec | null |
Returns
PlaySpec | null