• Creates a readonly val from a getter function and a listener function.

    Type Parameters

    • TValue = any

    Parameters

    • getValue: (() => TValue)

      A function that returns the current value.

    • onChange: ((notify) => undefined | void | ValDisposer)

      A function that takes a notify function and returns a disposer. The notify function should be called when the value changes.

        • (notify): undefined | void | ValDisposer
        • Parameters

          • notify: (() => void)
              • (): void
              • Returns void

          Returns undefined | void | ValDisposer

    • Optional config: ValConfig<TValue>

      custom config for the val.

    Returns ReadonlyVal<TValue>

    A readonly val.

    Example

    const prefersDark = window.matchMedia("(prefers-color-scheme: dark)");
    const isDarkMode$ = from(
    () => prefersDark.matches,
    notify => {
    prefersDark.addEventListener("change", notify);
    return () => prefersDark.removeEventListener("change", notify);
    },
    );