@tinyactors/scxmljs
    Preparing search index...

    Class Session

    A session with the sandboxed data model (QuickJS/WebAssembly).

    Constructing one directly requires QuickJS to be loaded: await loadQuickJS() once first (createSession does it for you). Use this to create many sessions synchronously from one compiled model.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    clock: Clock

    The clock this session schedules on (delayed sends, deferred event processing).

    datamodel: DataModel

    The session's data model (advanced: evaluate expressions against the running chart, for example in tools).

    done: Promise<unknown> = ...

    Resolves when the session terminates, with the top-level final state's <donedata> (or undefined). It never rejects: a session that is cancelled or disposed first resolves with undefined — check session.cancelled to tell the two apart.

    model: Model

    The compiled chart the session runs.

    sessionId: string

    The session's id: _sessionid, and the address #_scxml_<sessionId>.

    Accessors

    • get cancelled(): boolean

      True when the session was ended by cancel() / dispose() rather than by reaching a final state.

      Returns boolean

    • get configuration(): StateNode[]

      Active states, document order.

      Returns StateNode[]

    • get invocations(): Invocation[]

      Active invocations: what <invoke> started and is still running, with the child session for SCXML invokes.

      Returns Invocation[]

    • get parentSession(): ParentInvocation | undefined

      The invoking session and invokeid, when this session was started by <invoke>.

      Returns ParentInvocation | undefined

    • get signal(): AbortSignal

      Aborts when the session terminates (final state, cancel) or is disposed. Pass it to addEventListener(…, { signal }) to tie host listeners to the session.

      Returns AbortSignal

    • get status(): "done" | "running" | "idle"

      "idle" before start(), "running", or "done" once the session has terminated (see cancelled for how).

      Returns "done" | "running" | "idle"

    Methods

    • The ids of the active states, document order.

      Returns string[]

    • Listen to a session event (microstep, macrostep, log, error, send, invoke, child, done), typed through SessionEventMap. A listener that throws is logged and can't abort a step.

      Type Parameters

      Parameters

      Returns void

    • Any other event type (untyped).

      Parameters

      • type: string
      • listener: EventListenerOrEventListenerObject | null
      • Optionaloptions: boolean | AddEventListenerOptions

      Returns void

    • Declarative sends by event delegation on root: elements with data-scxml-send (see bind in bridge.ts for the attribute rules). Returns a disposer; also disconnects on options.signal abort and when the session terminates.

      Parameters

      Returns () => void

    • Cancel the session from outside (like a parent cancelling an invoke): it exits all states, running onexit handlers, without a done event.

      Returns void

    • Send scxmlEvent whenever target fires domType (space-separated types or an array). scxmlEvent may be a function of the DOM event (null/undefined: don't send); data computes the event data. Returns a disposer; also disconnects on options.signal abort and when the session terminates.

      Parameters

      • target: EventTarget
      • domType: string | readonly string[]
      • scxmlEvent: EventNameMapper
      • Optionaldata: (e: Event) => unknown
      • Optionaloptions: ConnectOptions

      Returns () => void

    • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order.

      MDN Reference

      Parameters

      • event: Event

      Returns boolean

    • Release everything the session holds: cancels it if it is still running (running onexit handlers, no done event), stops its timers, removes listeners installed by connect() / bind() and attributes set by reflect, frees the data model context and leaves the session registry. done resolves (with undefined if it hadn't finished). Safe to call more than once; the session can't be used afterwards.

      Returns void

    • Whether the state with this id is active.

      Parameters

      • id: string

      Returns boolean

    • Remove a listener added with addEventListener.

      Type Parameters

      Parameters

      Returns void

    • Any other event type (untyped).

      Parameters

      • type: string
      • listener: EventListenerOrEventListenerObject | null
      • Optionaloptions: boolean | EventListenerOptions

      Returns void

    • Enqueue an external event.

      Parameters

      • name: string
      • Optionaldata: unknown

      Returns void

    • Resolves once the session is idle: both queues are empty and no processing is scheduled (or the session has terminated / not started). Pending delayed <send>s and replies still owed by I/O processors or invoked services do not count — the session is idle while it waits for them.

      It is driven by the session's own scheduler, never by polling: with a VirtualClock, nothing happens until the host calls clock.run(), and the promise resolves during that call.

      Returns Promise<void>

    • A plain-data copy of every variable declared with <data>, keyed by id.

      Values are copied out of the data model the way JSON would copy them: objects and arrays are copied, functions are dropped, dates become ISO strings, and properties whose value is undefined may be omitted. XML values are serialised strings with the sandboxed data model and DOM nodes with the trusted one. Variables created by <script> without <data> are not included. After dispose() it returns {}.

      Returns Record<string, unknown>

    • interpret() — spec Appendix D.

      Returns this

    • An async iterator over macrosteps, ending when the session terminates (or options.signal aborts). Macrosteps are buffered, so none are lost while the consumer is busy.

      for await (const step of session.steps()) render(step.configuration);
      

      Parameters

      • options: { signal?: AbortSignal } = {}

      Returns AsyncIterableIterator<MacrostepEvent>

    • Resolves with the configuration at the first moment what holds: immediately, after a macrostep, or on entering a top-level final state (the configuration is cleared right after that, per the spec).

      what: a state id (active), several ids (all active) or a predicate. Rejects with options.signal.reason on abort, a TimeoutError DOMException after timeoutMs (measured on the session's clock), or an Error when the session terminates first.

      Parameters

      Returns Promise<StateNode[]>