Uneventful
    Preparing search index...

    Create a computed signal from a function, method, or function-returning function

    Expression Returns Behavior
    fn(() => T) Signal<T> Create a computed signal
    fn``(() => T) Signal<T> Same, but with call site caching[1]
    fn(ob => () => T) ob => T Create a function that gets the result of a per-object computed signal
    fn``(ob => () => T) ob => T Same, but with call site caching[1]
    @fn method(): T T Decorate[2] a method to act as a computed signal

    1. fn``(...) is shorthand for $``(() => fn(...)) [3]. That is, it acts just like any other call to fn, except that it only runs at most once per code location in a given signal function. The result is then cached and returned for every subsequent call from that specific location in the same signal function. ↩︎

    2. Both TC39 decorators and "legacy" TypeScript/Babel decorators are supported. ↩︎

    3. $``() is the lazy constant operator. It allows for an expression to only be evaluated once during the life of an enclosing signal, by caching the result on its first invocation. ↩︎

    • Create a signal that computes a value based on other signals. (Can also be used as a method decorator via @fn, with either TC39 or "Legacy" decorators.)

      Type Parameters

      • Result

        The type of value the created signal will provide.

      Parameters

      • compute: () => Result

        The function that will be called to compute the result, if the signals it used in its last invocation have changed since then.

      Returns Signal<Result>

      A signal that returns a cached value or recomputes it as necessary, and will be tracked as a dependency for other signals, rules, or effects, when they use it in their calculations.

    • Create a parameterized reactive function that tracks separate dependencies and caching state for each object it's called on.

      Type Parameters

      • Instance extends object

        The type of object the created function will be used with

      • Result

        The type of result the created function will return

      Parameters

      • factory: (obj: Instance) => () => Result

        A function that will be called with each new instance passed to the one-argument reactive function. It must return a zero-argument function, customized to compute the value for the instance it was given.

      Returns (obj: Instance) => Result

      a one-argument reactive function that is shorthand for looking up and returning the value of a cached signal customized for the given argument.

      That is, given rf = fn(a => () => a.bar), calling rf(foo) is equivalent to calling fn(() => foo.bar)(), except that each foo gets its own fn(() => foo.bar) signal cached, so that dependencies can be properly tracked per instance.