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
- RFC Play v1 Section 5.3
- Routable for routing capability
- Viewable for view rendering capability
Extends
Actor<TLogic>
Type Parameters
| Type Parameter | Description |
|---|---|
TLogic extends AnyActorLogic | XState 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
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
_parent? | public | AnyActorRef | - | Actor._parent | node_modules/xstate/dist/declarations/src/createActor.d.ts:33 |
clock | public | Clock | The clock that is responsible for setting and clearing timeouts, such as delayed events and transitions. | Actor.clock | node_modules/xstate/dist/declarations/src/createActor.d.ts:25 |
id | public | string | The unique identifier for this actor relative to its parent. | Actor.id | node_modules/xstate/dist/declarations/src/createActor.d.ts:28 |
logic | public | TLogic | - | Actor.logic | node_modules/xstate/dist/declarations/src/createActor.d.ts:18 |
options | public | Readonly<ActorOptions<TLogic>> | - | Actor.options | node_modules/xstate/dist/declarations/src/createActor.d.ts:26 |
ref | public | ActorRef<SnapshotFrom<TLogic>, EventFromLogic<TLogic>, EmittedFrom<TLogic>> | - | Actor.ref | node_modules/xstate/dist/declarations/src/createActor.d.ts:34 |
sessionId | public | string | The globally unique process ID for this invocation. | Actor.sessionId | node_modules/xstate/dist/declarations/src/createActor.d.ts:38 |
src | public | | string | AnyActorLogic | - | Actor.src | node_modules/xstate/dist/declarations/src/createActor.d.ts:42 |
state | abstract | State<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 |
system | public | AnyActorSystem | The system to which this actor belongs. | Actor.system | node_modules/xstate/dist/declarations/src/createActor.d.ts:40 |
systemId | public | string | undefined | - | Actor.systemId | node_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
- Actor.subscribe to subscribe to an actor’s snapshot values.
- Actor.getPersistedSnapshot to persist the internal state of an actor (which is more than just a snapshot).
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
| Parameter | Type |
|---|---|
type | TType |
handler | (emitted) => void |
Returns
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
| Parameter | Type | Description |
|---|---|---|
event | object & 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 intentactor.send({ type: "auth.login", userId: "123" });// Actor's guards determine if event is allowedRemarks
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
| Parameter | Type | Description |
|---|---|---|
observer | Observer<SnapshotFrom<TLogic>> | Either a plain function that receives the latest snapshot, or an observer object whose .next(snapshot) method receives the latest snapshot |
Returns
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 functionconst subscription = actor.subscribe((snapshot) => { console.log(snapshot);});// Observer as an objectconst 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 observersubscription.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
| Parameter | Type |
|---|---|
nextListener? | (snapshot) => void |
errorListener? | (error) => void |
completeListener? | () => void |
Returns
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 functionconst subscription = actor.subscribe((snapshot) => { console.log(snapshot);});// Observer as an objectconst 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 observersubscription.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
| Name | Type | Defined in |
|---|---|---|
id | string | node_modules/xstate/dist/declarations/src/createActor.d.ts:137 |
xstate$$type | number | node_modules/xstate/dist/declarations/src/createActor.d.ts:136 |
Inherited from
Actor.toJSON;