@nkeff/cardboard-js
    Preparing search index...

    Function compute

    • Creates a new Observable whose value is derived from another Observable. The new Observable automatically updates and notifies listeners whenever the source Observable changes.

      Type Parameters

      • T
      • K

      Parameters

      • other: IObservable<T>

        The source Observable to derive the value from.

      • transform: (val: T) => K

        A function that takes the value of the source Observable and returns the derived value.

      Returns IObservable<K>

      A new Observable that will contain the derived value.

      const value = createObservable(2);
      // Create a derived observable that is true if value > 5
      const isGreater = compute(value, (v) => v > 5);
      // isGreater.value == false
      value.dispatch(6);
      // isGreater.value == true