Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AbstractRuntime<Events> Abstract

Skeletal implementation of IRuntime that uses a root Collab.

Type Parameters

Hierarchy

Implements

Index

Constructors

Properties

isRuntime: true
replicaID: string

A unique ID for this replica (copy of a Collabs document).

Methods

  • Internal (Collab.send) use only.

    Sends the given message on behalf of child. In general, this parent is then responsible for delivering the given message to Collab.receive on each replica of child, with guarantees set by the runtime.

    Parameters

    Returns void

  • emit<K>(eventName: K, event: Events[K]): void
  • Emits an event, which triggers all the registered event handlers.

    Event handlers are called in the order they are added. Errors in event handlers are captured and logged (with console.error), not propagated to the caller.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • eventName: K

      Name of the event to emit.

    • event: Events[K]

      Event object to pass to the event handlers.

    Returns void

  • fromID<C>(id: CollabID<C>): undefined | C
  • Inverse of idOf.

    Specifically, given a CollabID returned by idOf on some replica of this runtime, returns this replica's copy of the original collab. If that Collab does not exist (e.g., it was deleted or it is not present in this program version), returns undefined.

    Type Parameters

    Parameters

    Returns undefined | C

  • Returns a CollabID for the given Collab.

    The CollabID may be passed to fromID on any replica of this runtime to obtain that replica's copy of collab.

    Type Parameters

    Parameters

    • collab: C

    Returns CollabID<C>

  • on<K>(eventName: K, handler: ((event: Events[K], caller: AbstractRuntime<Events>) => void), options?: { once?: boolean }): (() => void)
  • Registers an event handler that is triggered when the event happens.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • eventName: K

      Name of the event to listen on.

    • handler: ((event: Events[K], caller: AbstractRuntime<Events>) => void)

      Callback that handles the event.

    • Optional options: { once?: boolean }
      • Optional once?: boolean

        If true, the event handler is triggered at most once (the next time the event happens), then unsubscribed.

    Returns (() => void)

    An "off" function that removes the event handler when called.

      • (): void
      • Registers an event handler that is triggered when the event happens.

        Returns void

        An "off" function that removes the event handler when called.

  • setRootCollab<C>(rootCallback: ((init: InitToken) => C)): C

Generated using TypeDoc