@kayahr/signal

    Function toSignal

    • Simply returns the given signal. This signature is just present so toSignal can be used universally to create a signal from an arbitrary source, even when the source is already a signal.

      Type Parameters

      • T extends Signal<unknown>

        The signal type.

      Parameters

      • signal: T

        The signal to pass through.

      Returns T

      The given signal.

    • Creates a computed signal using the given compute function to update its value. This is equivalent to computed(fn);

      Type Parameters

      • T

        The signal value type.

      Parameters

      • compute: () => T

        The compute function called to calculate the actual value.

      • Optionaloptions: BaseSignalOptions<T>

        Optional signal options.

      Returns ComputedSignal<T>

      The creates computed signal.

    • Creates an ObserverSignal which observes the given observable, either using the given initial signal value or requiring the observable to emit an initial value on subscribe.

      To prevent memory leaks you must either manually destroy the signal with the ObserverSignal.destroy method or use a SignalContext which automatically destroys observer signals created within the context when the context is destroyed.

      Type Parameters

      • T

        The signal value type.

      Parameters

      • subscribable: Subscribable<T>

        The observable to subscribe to.

      • options: ObserverSignalOptions<T> & ({ initialValue: T } | { requireSync: true })

        Optional signal options.

      Returns ObserverSignal<T>

      The created observer signal.

    • Creates an ObserverSignal which observes the given observable. With no initialValue set and requireSync not set to true the signal value will include undefined as valid value. If you don't want that then either specify an initialValue in the signal options or use the requireSync option to define that the observable does emit a value synchronously on subscription.

      To prevent memory leaks you must either manually destroy the signal with the ObserverSignal.destroy method or use a SignalContext which automatically destroys observer signals created within the context when the context is destroyed.

      Type Parameters

      • T

        The signal value type.

      Parameters

      • subscribable: Subscribable<T>

        The observable to subscribe to.

      • Optionaloptions: ObserverSignalOptions<T>

        Optional signal options.

      Returns ObserverSignal<undefined | T>

      The created observer signal.

    • Creates a Signal from the given signal source, which can be an observable, a function or already a signal, which is then returned unchanged.

      Type Parameters

      • T

        The signal value type.

      Parameters

      • source: SignalSource<T>

        The signal source. If it is a function, then a ComputedSignal is created. If it is an observable, then an ObserverSignal is created. If the source is already a signal then it is returned as-is.

      • options: ObserverSignalOptions<T> & ({ initialValue: T } | { requireSync: true })

        Optional signal options. Ignored when source is a signal. If source is an observable then you may want to set the initialValue or requireSync option to prevent the signal value to be undefined initially.

      Returns Signal<T>

      The created signal.

    • Creates a Signal from the given signal source, which can be an observable, a function or already a signal, which is then returned unchanged.

      Type Parameters

      • T

        The signal value type.

      Parameters

      • source: SignalSource<T>

        The signal source. If it is a function, then a ComputedSignal is created. If it is an observable, then an ObserverSignal is created. If the source is already a signal then it is returned as-is.

      • Optionaloptions: ObserverSignalOptions<T>

        Optional signal options. Ignored when source is a signal. If source is an observable then you may want to set the initialValue or requireSync option to prevent the signal value to be undefined initially.

      Returns Signal<undefined | T>

      The created signal.

    MMNEPVFCICPMFPCPTTAAATR