Skip to content

Commit

Permalink
API Docs: Actor (#4420)
Browse files Browse the repository at this point in the history
* Actor#getSnapshot

* Actor#system

* Actor#delaySend: `@internal`

* Actor#cancel: `@internal`

* Actor comment
  • Loading branch information
audionerd authored Nov 2, 2023
1 parent a91fdea commit f4ca83a
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions packages/core/src/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ const defaultOptions = {
devTools: false
};

/**
* An Actor is a running process that can receive events, send events and change its behavior based on the events it receives, which can cause effects outside of the actor. When you run a state machine, it becomes an actor.
*/
export class Actor<TLogic extends AnyActorLogic>
implements ActorRef<EventFromLogic<TLogic>, SnapshotFrom<TLogic>>
{
Expand Down Expand Up @@ -125,6 +128,9 @@ export class Actor<TLogic extends AnyActorLogic>
*/
public sessionId: string;

/**
* The system to which this actor belongs.
*/
public system: ActorSystem<any>;
private _doneEvent?: DoneActorEvent;

Expand Down Expand Up @@ -547,7 +553,10 @@ export class Actor<TLogic extends AnyActorLogic>
this.system._relay(undefined, this, event);
}

// TODO: make private (and figure out a way to do this within the machine)
/**
* TODO: figure out a way to do this within the machine
* @internal
*/
public delaySend(params: {
event: EventObject;
id: string | undefined;
Expand All @@ -569,7 +578,10 @@ export class Actor<TLogic extends AnyActorLogic>
}
}

// TODO: make private (and figure out a way to do this within the machine)
/**
* TODO: figure out a way to do this within the machine
* @internal
*/
public cancel(sendId: string | number): void {
this.clock.clearTimeout(this.delayedEventsMap[sendId]);
delete this.delayedEventsMap[sendId];
Expand Down Expand Up @@ -599,6 +611,20 @@ export class Actor<TLogic extends AnyActorLogic>
return this;
}

/**
* Read an actor’s snapshot synchronously.
*
* @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 {@link Actor.subscribe} to subscribe to an actor’s snapshot values.
* @see {@link Actor.getPersistedState} to persist the internal state of an actor (which is more than just a snapshot).
*/
public getSnapshot(): SnapshotFrom<TLogic> {
return this._state;
}
Expand Down

0 comments on commit f4ca83a

Please sign in to comment.