Skip to content

Abstract Interface: AbstractActor<TLogic>

Documentation / @xmachines/play-solid-router / AbstractActor

Defined in: packages/play-actor/dist/abstract-actor.d.ts:173

Abstract base class for Play Architecture actors.

Extends XState Actor to maintain ecosystem compatibility (inspection, devtools) while enforcing minimal signal protocol for Actor ↔ Infrastructure communication.

The core protocol contains only:

  • state: Reactive state snapshot
  • send: Event dispatch method

Optional capabilities (routing, view rendering) are provided via interfaces:

  • Implement Routable for routing support
  • Implement Viewable for view rendering support

Concrete implementations created by @xmachines/play-xstate adapter.

Examples

Simple actor (no routing, no view)

class SimpleActor extends AbstractActor<AnyActorLogic> {
state = new Signal.State({...});
send(event) { ... }
}

Routable actor

class RoutableActor extends AbstractActor<AnyActorLogic> implements Routable {
state = new Signal.State({...});
currentRoute = new Signal.Computed(() => deriveRoute(this.state.get()));
send(event) { ... }
}

Full-featured actor (routing + view)

class PlayerActor extends AbstractActor<AnyActorLogic> implements Routable, Viewable {
state = new Signal.State({...});
currentRoute = new Signal.Computed(() => deriveRoute(this.state.get()));
currentView = new Signal.State(null);
catalog = {};
send(event) { ... }
}

See

Extends

Type Parameters

Type ParameterDescription
TLogic extends AnyActorLogicXState actor logic type (maintains type safety) Invariant: Actor Authority - Actor is the sole source of truth for state transitions. Invariant: Signal-Only Reactivity - Infrastructure observes via TC39 Signals. Invariant: Passive Infrastructure - Infrastructure reflects, never decides.

Properties

PropertyModifierTypeDescriptionInherited fromDefined in
_parent?publicAnyActorRef-Actor._parentnode_modules/xstate/dist/declarations/src/createActor.d.ts:33
clockpublicClockThe clock that is responsible for setting and clearing timeouts, such as delayed events and transitions.Actor.clocknode_modules/xstate/dist/declarations/src/createActor.d.ts:25
idpublicstringThe unique identifier for this actor relative to its parent.Actor.idnode_modules/xstate/dist/declarations/src/createActor.d.ts:28
logicpublicTLogic-Actor.logicnode_modules/xstate/dist/declarations/src/createActor.d.ts:18
optionspublicReadonly<ActorOptions<TLogic>>-Actor.optionsnode_modules/xstate/dist/declarations/src/createActor.d.ts:26
refpublicActorRef<SnapshotFrom<TLogic>, EventFromLogic<TLogic>, EmittedFrom<TLogic>>-Actor.refnode_modules/xstate/dist/declarations/src/createActor.d.ts:34
sessionIdpublicstringThe globally unique process ID for this invocation.Actor.sessionIdnode_modules/xstate/dist/declarations/src/createActor.d.ts:38
srcpublic| string | AnyActorLogic-Actor.srcnode_modules/xstate/dist/declarations/src/createActor.d.ts:42
stateabstractState<unknown>Reactive snapshot of current actor state. Typed as Signal.State<unknown> at the abstract level; concrete implementations narrow this to the actual snapshot type (e.g., Signal.State<AnyMachineSnapshot> in @xmachines/play-xstate’s PlayerActor). Infrastructure observes this signal to react to state changes without directly coupling to the Actor’s internal state machine implementation. Example // Infrastructure observes state signal const watcher = new Signal.subtle.Watcher(() => { console.log('Actor state changed:', actor.state.get()); }); watcher.watch(actor.state);-packages/play-actor/dist/abstract-actor.d.ts:193
systempublicAnyActorSystemThe system to which this actor belongs.Actor.systemnode_modules/xstate/dist/declarations/src/createActor.d.ts:40
systemIdpublicstring | undefined-Actor.systemIdnode_modules/xstate/dist/declarations/src/createActor.d.ts:36

Methods

[observable]()

observable: InteropSubscribable<SnapshotFrom<TLogic>>;

Defined in: node_modules/xstate/dist/declarations/src/createActor.d.ts:153

Returns

InteropSubscribable<SnapshotFrom<TLogic>>

Inherited from

Actor.[observable]

getPersistedSnapshot()

getPersistedSnapshot(): Snapshot<unknown>;

Defined in: node_modules/xstate/dist/declarations/src/createActor.d.ts:152

Obtain the internal state of the actor, which can be persisted.

Returns

Snapshot<unknown>

Remarks

The internal state can be persisted from any actor, not only machines.

Note that the persisted state is not the same as the snapshot from Actor.getSnapshot. Persisted state represents the internal state of the actor, while snapshots represent the actor’s last emitted value.

Can be restored with ActorOptions.state

See

https://stately.ai/docs/persistence

Inherited from

Actor.getPersistedSnapshot;

getSnapshot()

getSnapshot(): SnapshotFrom<TLogic>;

Defined in: node_modules/xstate/dist/declarations/src/createActor.d.ts:168

Read an actor’s snapshot synchronously.

Returns

SnapshotFrom<TLogic>

Remarks

The snapshot represent an actor’s last emitted value.

When an actor receives an event, its internal state may change. An actor may emit a snapshot when a state transition occurs.

Note that some actors, such as callback actors generated with fromCallback, will not emit snapshots.

See

Inherited from

Actor.getSnapshot;

on()

on<TType>(type, handler): Subscription;

Defined in: node_modules/xstate/dist/declarations/src/createActor.d.ts:115

Type Parameters

Type Parameter
TType extends any

Parameters

ParameterType
typeTType
handler(emitted) => void

Returns

Subscription

Inherited from

Actor.on;

send()

abstract send(event): void;

Defined in: packages/play-actor/dist/abstract-actor.d.ts:216

Send event to Actor

Infrastructure forwards user intents (navigation, domain events, custom events) as events to the Actor. The Actor’s state machine guards determine whether each event is valid from the current state.

Parameters

ParameterTypeDescription
eventobject & Record<string, unknown>Event object with type property (e.g., PlayEvent, PlayRouteEvent) Invariant: Actor Authority - Only Actor decides whether an event is valid.

Returns

void

Example

// Infrastructure forwards user intent
actor.send({ type: "auth.login", userId: "123" });
// Actor's guards determine if event is allowed

Remarks

Accepts any event object with a type property. Core events (PlayEvent) are in @xmachines/play, routing events (PlayRouteEvent) are in @xmachines/play-router.

Overrides

Actor.send;

start()

start(): this;

Defined in: node_modules/xstate/dist/declarations/src/createActor.d.ts:119

Starts the Actor from the initial state

Returns

this

Inherited from

Actor.start;

stop()

stop(): this;

Defined in: node_modules/xstate/dist/declarations/src/createActor.d.ts:123

Stops the Actor and unsubscribe all listeners.

Returns

this

Inherited from

Actor.stop;

subscribe()

Call Signature

subscribe(observer): Subscription;

Defined in: node_modules/xstate/dist/declarations/src/createActor.d.ts:113

Subscribe an observer to an actor’s snapshot values.

Parameters
ParameterTypeDescription
observerObserver<SnapshotFrom<TLogic>>Either a plain function that receives the latest snapshot, or an observer object whose .next(snapshot) method receives the latest snapshot
Returns

Subscription

Remarks

The observer will receive the actor’s snapshot value when it is emitted. The observer can be:

  • A plain function that receives the latest snapshot, or
  • An observer object whose .next(snapshot) method receives the latest snapshot
Examples
// Observer as a plain function
const subscription = actor.subscribe((snapshot) => {
console.log(snapshot);
});
// Observer as an object
const subscription = actor.subscribe({
next(snapshot) {
console.log(snapshot);
},
error(err) {
// ...
},
complete() {
// ...
},
});

The return value of actor.subscribe(observer) is a subscription object that has an .unsubscribe() method. You can call subscription.unsubscribe() to unsubscribe the observer:

const subscription = actor.subscribe((snapshot) => {
// ...
});
// Unsubscribe the observer
subscription.unsubscribe();

When the actor is stopped, all of its observers will automatically be unsubscribed.

Inherited from
Actor.subscribe;

Call Signature

subscribe(
nextListener?,
errorListener?,
completeListener?): Subscription;

Defined in: node_modules/xstate/dist/declarations/src/createActor.d.ts:114

Subscribe an observer to an actor’s snapshot values.

Parameters
ParameterType
nextListener?(snapshot) => void
errorListener?(error) => void
completeListener?() => void
Returns

Subscription

Remarks

The observer will receive the actor’s snapshot value when it is emitted. The observer can be:

  • A plain function that receives the latest snapshot, or
  • An observer object whose .next(snapshot) method receives the latest snapshot
Examples
// Observer as a plain function
const subscription = actor.subscribe((snapshot) => {
console.log(snapshot);
});
// Observer as an object
const subscription = actor.subscribe({
next(snapshot) {
console.log(snapshot);
},
error(err) {
// ...
},
complete() {
// ...
},
});

The return value of actor.subscribe(observer) is a subscription object that has an .unsubscribe() method. You can call subscription.unsubscribe() to unsubscribe the observer:

const subscription = actor.subscribe((snapshot) => {
// ...
});
// Unsubscribe the observer
subscription.unsubscribe();

When the actor is stopped, all of its observers will automatically be unsubscribed.

Inherited from
Actor.subscribe;

toJSON()

toJSON(): object;

Defined in: node_modules/xstate/dist/declarations/src/createActor.d.ts:135

Returns

object

NameTypeDefined in
idstringnode_modules/xstate/dist/declarations/src/createActor.d.ts:137
xstate$$typenumbernode_modules/xstate/dist/declarations/src/createActor.d.ts:136

Inherited from

Actor.toJSON;