Class Machine<T, R, W>

The core engine for running applications that interface with blockchain-driven architectures. Provides mechanisms for reading from and writing to the blockchain, as well as invoking app-specific methods.

Type Parameters

Hierarchy

  • EventEmitter
    • Machine

Constructors

  • Type Parameters

    Parameters

    • appClass: (new () => T)

      The class that represents the application's logic and state.

        • new (): T
        • Returns T

    • reader: R
    • writer: W

      The writer to persist data to the blockchain.

    • Optional recorder: Recorder
      Optional

    Returns Machine<T, R, W>

Properties

prefixed: string | boolean
instance: T
reader: R
writer: W
recorder?: Recorder
queue: default<default, QueueAddOptions> = ...
[_snapshot]: Snapshot

Methods

  • Parameters

    • event: string | symbol
    • listener: ((...args) => void)
        • (...args): void
        • Parameters

          • Rest ...args: any[]
            Rest

          Returns void

    Returns Machine<T, R, W>

  • Instructs the reader to begin dispatching events. Calls the reader's start function with the latest action id if present

    Returns void

  • Loads a snapshot into the state of the App instance. After calling this function, getInstance().state will equal that of the loaded snapshot

    Parameters

    • Optional id: string

      The Action.id of the snapshot to load

      Optional

    Returns Promise<void>

  • Gets a proxied version of the app instance where methods are wrapped to automatically write actions to the action storage.

    Access to instance.state is readonly via a cloned copy

    Returns WrappedType<T>

    The wrapped application instance.

  • Gets a proxied version of the app instance where methods are wrapped to automatically write events to the blockchain when invoked.

    Parameters

    Returns void

    The wrapped application instance.

  • Dispatches an action to the appropriate method on the app instance. Passed to a reader via the Reader.initialize function. Called by a reader to dispatch actions.

    Parameters

    • action: Action

      The action data.

    • additionalContext: any

      Additional context data that will be accessible from ctx.reader inside methods.

    Returns void

  • Return an array listing the events for which the emitter has registered listeners.

    Returns (string | symbol)[]

  • Return the listeners registered for a given event.

    Type Parameters

    • T extends string | symbol

    Parameters

    • event: T

    Returns ((...args) => void)[]

  • Return the number of listeners listening to a given event.

    Parameters

    • event: string | symbol

    Returns number

  • Calls each of the listeners registered for a given event.

    Type Parameters

    • T extends string | symbol

    Parameters

    • event: T
    • Rest ...args: any[]
      Rest

    Returns boolean

  • Type Parameters

    • T extends string | symbol

    Parameters

    • event: T
    • fn: ((...args) => void)
        • (...args): void
        • Parameters

          • Rest ...args: any[]
            Rest

          Returns void

    • Optional context: any
      Optional

    Returns Machine<T, R, W>

  • Add a one-time listener for a given event.

    Type Parameters

    • T extends string | symbol

    Parameters

    • event: T
    • fn: ((...args) => void)
        • (...args): void
        • Parameters

          • Rest ...args: any[]
            Rest

          Returns void

    • Optional context: any
      Optional

    Returns Machine<T, R, W>

  • Remove the listeners of a given event.

    Type Parameters

    • T extends string | symbol

    Parameters

    • event: T
    • Optional fn: ((...args) => void)
      Optional
        • (...args): void
        • Parameters

          • Rest ...args: any[]
            Rest

          Returns void

    • Optional context: any
      Optional
    • Optional once: boolean
      Optional

    Returns Machine<T, R, W>

  • Type Parameters

    • T extends string | symbol

    Parameters

    • event: T
    • Optional fn: ((...args) => void)
      Optional
        • (...args): void
        • Parameters

          • Rest ...args: any[]
            Rest

          Returns void

    • Optional context: any
      Optional
    • Optional once: boolean
      Optional

    Returns Machine<T, R, W>

  • Remove all listeners, or those of the specified event.

    Parameters

    • Optional event: string | symbol
      Optional

    Returns Machine<T, R, W>

Generated using TypeDoc