• A convenience function to create Readable store instances.

    Type Parameters

    • T

    Parameters

    • value: T

      Initial value of a readable store.

    • options: StoreOptions<T> | OnUseFn<T> = {}

      Either an object with store options, or directly the onUse function.

      The onUse function is a function called when the number of subscribers changes from 0 to 1 (but not called when the number of subscribers changes from 1 to 2, ...).

      If a function is returned, it will be called when the number of subscribers changes from 1 to 0.

    Returns ReadableSignal<T>

    Example: Sample with an onUse function

    const clock = readable("00:00", setState => {
    const intervalID = setInterval(() => {
    const date = new Date();
    setState(`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`);
    }, 1000);

    return () => clearInterval(intervalID);
    });

Generated using TypeDoc