Function: toAtomState()
API / @xmachines/play-actor / toAtomState
function toAtomState(state): Record<string, unknown>;Defined in: packages/play-actor/src/provider-guards.ts:39
Converts the state field of a spec into a plain object for createAtom, in a safe way.
spec.state has the type unknown in PlaySpec. At run time it is null,
undefined, a primitive, or a plain object, and this depends on the value that
the author of the machine put in the view spec. createAtom requires a plain
object as its first value, because every other value makes a broken store at run
time.
The function accepts a plain object only, which means that its prototype is
Object.prototype or null, and it returns that object without a change. Every
other value becomes a new {}: null, undefined, a primitive, an array, an
instance of a class, and a built-in object such as a Date, a Map, or a Set. A
broken store therefore never appears at run time.
Parameters
| Parameter | Type | Description |
|---|---|---|
state | unknown | The raw spec.state value of a PlaySpec. |
Returns
Record<string, unknown>
state itself when it is a plain object. In every other case, a new empty object.