Class Consumable<T>

A class that holds a value. Listeners can be attached and whenever a new value is dispatched, the listeners are called.

Type Parameters

  • T = any

Hierarchy

Implements

Constructors

Properties

_destroyer?: (() => void)

Type declaration

    • (): void
    • Returns void

_listeners: ((data) => void)[] = []

Type declaration

    • (data): void
    • Parameters

      • data: undefined | T

      Returns void

_value: T

Accessors

Methods

  • Create a new Consumable that intersects this Consumable. The new Consumable updates its value based on this Consumable.

    Type Parameters

    • K

    Parameters

    • intersector: ((val) => K)
        • (val): K
        • Parameters

          • val: T

          Returns K

    Returns any

    Example

    const value = createConsumable(2);
    const isGreater = value.intersect((value) => value > 5);
    // > isGreater == false;
    value.dispatch(6);
    // > isGreater == true;
  • Parameters

    • fn: ((data?) => void)
        • (data?): void
        • Parameters

          • Optional data: T

          Returns void

    Returns void

Generated using TypeDoc