• Create a computed val that subscribes to other vals dynamically.

    The get function passed to the effect callback can be used to get the current value of a Val and subscribe to it. The effect callback will be re-evaluated whenever the dependencies change. Stale dependencies are unsubscribed automatically.

    Type Parameters

    • TValue = any

    Parameters

    • effect: ((get) => TValue)

      The effect function which will be called immediately and whenever the dependencies change.

    • Optional config: ValConfig<TValue>

      Optional val config.

    Returns ReadonlyVal<TValue>

    A computed val.

    Example

    import { compute, val } from "value-enhancer";

    const a$ = val(1);
    const b$ = val("b");
    const c$ = val("c");
    const s$ = compute(get => (get(a$) % 2 === 0 ? get(b$) : get(c$)));