Class ChipBase<ChipBaseEvents>Abstract

A base class for creating chips that reduces boilerplate code. To use it, simply override some or all of the following protected methods:

  • _onActivate()
  • _onTick()
  • _onTerminate()
  • _onPause()
  • _onResume() In these methods, you can access the _chipContext _lastTickInfo properties to obtain the latest information there.

In addition, you can subscribe to events using _subscribe() in a way that automatically unsubscribes when the chip is terminated.

Type Parameters

Hierarchy

Implements

Constructors

Properties

_chipContext: Readonly<Record<string, any>>
_eventListeners: IEventListener[] = []
_inputSignal?: Signal<string>
_lastTickInfo: TickInfo
_listeners: Listener<ChipBaseEvents, any>[]
_outputSignal?: Signal<string>
_reloadMemento?: ReloadMemento
_state: ChipState = "inactive"

Accessors

  • get chipContext(): Readonly<Record<string, any>>
  • Returns Readonly<Record<string, any>>

Methods

  • Template method called by activate().

    Returns void

  • Template method called by pause().

    Returns void

  • Template method called by resize()

    Parameters

    • width: number
    • height: number

    Returns void

  • Template method called by resume().

    Returns void

  • Template method called by terminate().

    Returns void

  • Template method called by tick().

    Returns void

  • Start listening to events of a certain type emitted by an object. The callback will be called with the chip as this. Works by default for both NodeJS- and DOM-style events. If you are interfacing with a different event system, you can provide a subscriptionHandler that knows how to handle it.

    Type Parameters

    • Emitter extends object

    • EventNames extends BaseEventNames

    • EventName extends string

    Parameters

    • emitter: Emitter
    • eventName: EventName
    • cb: ((this, ...args) => void)
        • (this, ...args): void
        • Parameters

          • this: ChipBase<ChipBaseEvents>
          • Rest ...args: EventNames[EventName]

          Returns void

    • Optional subscriptionHandler: SubscriptionHandler

    Returns void

  • Listen to a single event emitted by an object, then stop. The callback will be called with the chip as this. Works by default for both NodeJS- and DOM-style events. If you are interfacing with a different event system, you can provide a subscriptionHandler that knows how to handle them.

    Type Parameters

    • Emitter extends object

    • EventNames extends BaseEventNames

    • EventName extends string

    Parameters

    • emitter: Emitter
    • eventName: EventName
    • cb: ((this, ...args) => void)
        • (this, ...args): void
        • Parameters

          • this: ChipBase<ChipBaseEvents>
          • Rest ...args: EventNames[EventName]

          Returns void

    • Optional subscriptionHandler: SubscriptionHandler

    Returns void

  • Unsubscribe to a set of events. By default, unsubscribes to everything. If emitter, event, or cb is provided, unsubscribe only to those.

    Parameters

    • Optional emitter: NodeEventSource
    • Optional event: string
    • Optional cb: ((...args) => void)
        • (...args): void
        • Parameters

          • Rest ...args: unknown[]

          Returns void

    Returns void

  • Activate the chip, with a provided context and input signal. Should only be called from an inactive state

    Parameters

    • tickInfo: TickInfo
    • chipContext: Readonly<Record<string, any>>
    • Optional inputSignal: Signal<string>
    • Optional reloadMemento: ReloadMemento

    Returns void

  • Type Parameters

    • Name extends string | number | symbol

    Parameters

    • name: Name
    • Rest ...params: ChipBaseEvents[Name]

    Returns void

  • Type Parameters

    • Name extends string | number | symbol

    Parameters

    • Optional name: Name
    • Optional run: ListenerFunction<ChipBaseEvents, Name>

    Returns void

  • Type Parameters

    • Name extends string | number | symbol

    Parameters

    • name: Name
    • run: ListenerFunction<ChipBaseEvents, Name>

    Returns void

  • Type Parameters

    • Name extends string | number | symbol

    Parameters

    • name: Name
    • run: ListenerFunction<ChipBaseEvents, Name>

    Returns void

  • Pause the chip, informing it that it won't receive ticks for a while

    Returns void

  • Terminate the chip. Should only be called from an active or paused state

    Parameters

    • outputSignal: Signal<string> = ...

    Returns void

  • Update the chip, provided a new time

    Parameters

    Returns void

Generated using TypeDoc