• Create a cached version of a function. The returned callable is also a Signal.

    Note: If the supplied function has a non-zero .length (i.e., it explicitly takes arguments), it is assumed to be a Source, and the second calling signature below will apply, even if TypeScript doesn't see it that way!)

    Type Parameters

    • T

    Parameters

    • compute: (() => T)
        • (): T
        • Returns T

    Returns Signal<T>

  • If the supplied function has a non-zero .length (i.e., it explicitly takes arguments), it is assumed to be a Source, and the second argument is a default value for the created signal to use as default value until the source produces a value.

    The source will be subscribed only while the signal is subscribed as a stream, or observed (directly or indirectly) by a rule. While subscribed, the signal will update itself with the most recent value produced by the source, triggering rules or events as appropriate if the value changes. When the signal is once again unobserved (or if the source ends without an error), its value will revert to the supplied default.

    If the source ends with an error, however, then the cached function will throw that error whenever called, until/unless it becomes unobserved again. (And thus reverts to the default value once more.)

    Type Parameters

    • T

    Parameters

    • source: Source<T>

      A Source providing data which will become this signal's value

    • Optional defaultVal: T

      The value to use when the signal is unobserved or waiting for the first item from the source.

    Returns Signal<T>

  • Type Parameters

    Parameters

    • signal: T

    Returns T