Class IntControl

Hierarchy (view full)

Constructors

Properties

disabled: MutCell<boolean> = ...
id: string = ...
max: number = Number.MAX_SAFE_INTEGER
min: number = Number.MIN_SAFE_INTEGER
source: MutCell<number>

Accessors

  • get defined(): Cell<boolean>
  • Create a cell the value of which is true if this cell's value is not null or undefined, false otherwise.

    Returns Cell<boolean>

    A cell.

  • get not(): Cell<boolean>
  • Create a cell that negates the value of this cell using the ! operator.

    Returns Cell<boolean>

    A negating cell.

  • get undefined(): Cell<boolean>
  • Create a cell the value of which is true if this cell's value is null or undefined, false otherwise.

    Returns Cell<boolean>

    A cell.

  • get value(): T
  • Returns T

  • set value(value): void
  • Set the cell's value. This emits the new value to all observers.

    Parameters

    • value: T

      The new value.

    Returns void

Methods

  • Convert this cell to an immutable cell. The resulting will no longer be an instance of MutCell but will still update its value whenever this cell is updated.

    Returns Cell<number>

  • Parameters

    • Optional onrejected: ((reason) => void)
        • (reason): void
        • Parameters

          • reason: unknown

          Returns void

    Returns Cell<undefined | number>

  • Create a two-way binding that modified values in both directions. The resulting cell is mutable and any modification of it will also result in an update of this cell.

    Type Parameters

    • T2

    Parameters

    • encode: ((value) => T2)

      Applied to the value of this cell to get the value of the resulting cell.

        • (value): T2
        • Parameters

          • value: number

          Returns T2

    • decode: ((value) => number)

      Applied to the value of the resulting cell to update the value of this cell.

        • (value): number
        • Parameters

          Returns number

    Returns MutCell<T2>

    Example

    const a = bind(1);
    const b = a.bimap(x => x + 1, y => y - 1);

    expect(b.value).toBe(2);

    a.value = 5;
    expect(b.value).toBe(6);

    b.value = 3;
    expect(a.value).toBe(2);
  • Create a cell tthe value of which is true if this cell's value is equal to the given value or the value of the given cell, false otherwise.

    Type Parameters

    • T2 extends undefined | number

    Parameters

    • other: T2 | Cell<T2>

      A value or cell to compare the value of this cell to.

    Returns Cell<boolean>

    A cell.

  • Create a cell that applies a function to the value of this cell. The function must return a cell.

    Type Parameters

    • T2

    Parameters

    • f: ((value) => Cell<T2>)

      The function apply to the cell value.

    Returns Cell<T2>

    A flat mapping cell.

  • Get the cells current value and attach an observer. The observer function is called once with the current value immediately upon calling this method.

    Parameters

    • observer: CellObserver<number>

      The observer function to attach.

    Returns (() => void)

    A function that can be called to detach the observer. Alternatively unobserve can be called.

      • (): void
      • Returns void

  • Create a cell that applies a function to the value of this cell.

    The function will be called whenever the value property of the resulting cell is accessed. If the resulting cell is being observed, the function will also be called once each time the value of this cell changes.

    Type Parameters

    • T2

    Parameters

    • f: ((value) => T2)

      The function to apply to the cell value.

        • (value): T2
        • Parameters

          • value: number

          Returns T2

    Returns Cell<T2>

    A cell.

  • Create a cell that applies a function to the value of this cell, but only when the value is not null or undefined.

    The function will be called whenever the value property of the resulting cell is accessed. If the resulting cell is being observed, the function will also be called once each time the value of this cell changes.

    Type Parameters

    • T2

    Parameters

    • f: ((value) => T2)

      The function apply to the cell value.

        • (value): T2
        • Parameters

          • value: number

          Returns T2

    Returns Cell<undefined | T2>

    A mapping cell.

  • Attach an observer.

    Parameters

    • observer: CellObserver<number>

      The observer function to attach.

    Returns (() => void)

    A function that can be called to detach the observer. Alternatively unobserve can be called.

      • (): void
      • Returns void

  • Create a promise that resolves with the first non-null, non-undefined value of this cell. If the value of this cell is not null or undefined the method returns a resolved Promise with the value.

    Returns Promise<number>

    A promise that resolves when the value of this cell is not null or undefined.

  • Update the cell's value via a function.

    Type Parameters

    • T2

    Parameters

    • mutator: ((value) => T2)

      A function that modifies the value of this cell.

        • (value): T2
        • Parameters

          • value: number

          Returns T2

    Returns T2

    If the mutator function returns a value, that value is returned by update as well.

    Example

    const a = cell({b: 5});
    a.update(a => a.b = 10);
    expect(a.value.b).toBe(10);
  • Same as update but the function is only applied if the value of the cell is not null or undefined.

    Type Parameters

    • T2

    Parameters

    • mutator: ((value) => T2)
        • (value): T2
        • Parameters

          • value: number

          Returns T2

    Returns undefined | T2

  • Create a cell from an existing observable (e.g. an Emitter) and an initial value.

    N.B. Unless observed, the value of the resulting cell will not update when the observable emits events.

    Type Parameters

    • T

    Parameters

    • observable: Observable<T>

      An observable.

    • initialValue: T

      The initial value of the cell.

    Returns Cell<T>

    A cell.