Skip to content

Interface: PlayActor<TSnapshot, TEvent>

API / @xmachines/play-solid-router / PlayActor

Defined in: play-actor/src/play-actor.ts:75

The actor contract of the Play Architecture. It names NO engine.

An actor of XMachines holds exactly two things, and this interface names both: the reactive snapshot, and the typed event dispatch. A state machine library is the concern of an adapter, and @xmachines/play-xstate is the adapter of XState v5.

Both type parameters carry their real type through, and neither one erases it. AbstractActor declares Signal.State<unknown>, so every consumer of a snapshot reads unknown and asserts its way back.

A capability is optional, and each one lives with the package that holds its shared machinery: Routable is in @xmachines/play-router, and Viewable is in @xmachines/play-view. Neither one names an engine either, and neither one implies the other.

Example

import type { PlayActor } from "@xmachines/play-actor";
import type { Viewable } from "@xmachines/play-view";
// A renderer reads the view capability and the send of the contract. It names no
// engine, and it keeps the event union of the machine.
function mount<TSnapshot, TEvent extends ActorEvent>(
actor: PlayActor<TSnapshot, TEvent> & Viewable,
): void {
actor.currentView.get();
}

Type Parameters

Type ParameterDefault typeDescription
TSnapshotunknownThe type of the snapshot that state holds, for example SnapshotFrom<TMachine>.
TEvent extends ActorEventActorEventThe event union that send accepts, for example EventFromLogic<TMachine>.

Properties

PropertyModifierTypeDescriptionDefined in
statereadonlyState<TSnapshot>The reactive snapshot of the current actor state. The infrastructure observes this signal, and it reacts to each state change. It therefore holds no coupling to the internal state machine of the actor.play-actor/src/play-actor.ts:82

Methods

send()

send(event): void;

Defined in: play-actor/src/play-actor.ts:90

Sends an event to the actor.

TEvent gives the type safety: a concrete adapter binds it to the event union of its own machine, and the compiler then refuses an event that the machine does not declare.

Parameters

ParameterType
eventTEvent

Returns

void