Class Variable<V, C>

An aggregate helper class for widgets that contain a variable with a specified type which is intended to be controlled by the user.

Useful for implementing widgets such as sliders, checkboxes, text input, etc...

Type Parameters

  • V

    The type of value.

  • C extends CallableFunction = VariableCallback<V>

    The type of a callback function. Should not be passed manually.

Hierarchy

Constructors

Properties

Accessors

Methods

Constructors

  • Create a new Variable.

    Type Parameters

    Parameters

    • initialValue: V

      The initial value of this variable. Sets _value.

    • Optional callback: C

      A callback for when the variable changes. Equivalent to calling watch after creating the variable, but allows for variables to created inline.

    • callNow: boolean = true

      If true, the callback will be called once immediately after it's registered, unless the callback is already registered. Doesn't apply if no callback was passed.

    Returns Variable<V, C>

Properties

_value: V

The current value, for internal use.

callbacks: Set<C> = ...

The function callbacks called when the value is changed

Accessors

Methods

  • Check if a callback is registered to this variable.

    Parameters

    • callback: C

    Returns boolean

  • Sets _value. Does nothing if the value is already the one specified.

    Returns

    Returns true if the value was changed, false if not

    Parameters

    • value: V
    • notify: boolean = true

      If true, then the callbacks are called.

    Returns boolean

  • Unregister a previously registered callback from this variable.

    Parameters

    • callback: C

    Returns boolean

  • Register a callback to this variable. When the value is changed, the callback will be called.

    Parameters

    • callback: C
    • callNow: boolean = true

      If true, the callback will be called once immediately after it's registered, unless the callback is already registered.

    Returns boolean

Generated using TypeDoc