Class ContextProvider

Base class for chips that contain other chips

Events:

  • activatedChildChip(chip: Chip, context: ChipContext, signal: Signal)
  • terminatedChildChip(chip: Chip)

Hierarchy (view full)

Constructors

Properties

_childChips: Record<string, Chip>
_chipContext: Readonly<Record<string, any>>
_context: Record<string, ChipResolvable>
_eventListeners: IEventListener[] = []
_inputSignal: Signal
_lastTickInfo: TickInfo
_outputSignal: Signal
_reloadMemento?: ReloadMemento
_state: ChipState = "inactive"
prefixed: string | boolean

Accessors

  • get children(): Record<string, Chip>
  • Children of this chip, if any

    Returns Record<string, Chip>

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

  • get outputSignal(): Signal
  • Once the chip is terminated, contains the signal

    Returns Signal

Methods

  • 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.

    Parameters

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

          • Rest ...args: any[]

          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.

    Parameters

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

          • Rest ...args: any[]

          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: object
    • 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

    Returns void

  • Type Parameters

    • T extends string | symbol

    Parameters

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

          • Rest ...args: any[]

          Returns void

    • Optional context: any

    Returns this

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

    Type Parameters

    • T extends string | symbol

    Parameters

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

    Returns boolean

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

    Returns (string | symbol)[]

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

    Parameters

    • event: string | symbol

    Returns number

  • Return the listeners registered for a given event.

    Type Parameters

    • T extends string | symbol

    Parameters

    • event: T

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

  • Type Parameters

    • T extends string | symbol

    Parameters

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

          • Rest ...args: any[]

          Returns void

    • Optional context: any
    • Optional once: boolean

    Returns this

  • Add a listener for a given event.

    Type Parameters

    • T extends string | symbol

    Parameters

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

          • Rest ...args: any[]

          Returns void

    • Optional context: any

    Returns this

  • 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[]

          Returns void

    • Optional context: any

    Returns this

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

    Parameters

    Returns void

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

    Parameters

    • Optional event: string | symbol

    Returns this

  • Remove the listeners of a given event.

    Type Parameters

    • T extends string | symbol

    Parameters

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

          • Rest ...args: any[]

          Returns void

    • Optional context: any
    • Optional once: boolean

    Returns this

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

    Parameters

    Returns void

  • By default, updates all child chips and remove those that have a signal Overload this method in subclasses to change the behavior

    Parameters

    Returns void

Generated using TypeDoc