Interface SignalOptions<T>

An object that stores the options of the signal to be created.

interface SignalOptions<T> {
    equal?: false | ((value: T, prevValue?: T) => unknown);
    name?: string;
    onActivate?: ((value: T) => void) | ((value: T) => ((value: T) => void));
    onCleanup?: ((value: T) => void);
    onCreate?: ((value?: T) => void);
    onDeactivate?: ((value: T) => void);
    onException?: ((e: unknown, prevValue?: T) => void);
    onUpdate?: ((value: T, prevValue?: T) => void);
}

Type Parameters

  • T

Properties

equal?: false | ((value: T, prevValue?: T) => unknown)

An equality function used to check whether the value of the signal has been changed. Default is Object.is.

A new value of the signal.

A previous value of the signal.

Truthy if the values are equal, falsy otherwise.

name?: string

A name of the signal. Can be accessed inside a lifecycle function via this.

onActivate?: ((value: T) => void) | ((value: T) => ((value: T) => void))

A function called when the first subscriber or the first active dependent signal appears.

The current value of the signal.

A function to override onDeactivate option.

onCleanup?: ((value: T) => void)

A function called each time before the signal value is calculated and when the signal is going to be deactivated. Useful to cleanup subscriptions and timers created during computation.

Type declaration

    • (value): void
    • Parameters

      • value: T

        The current value of the signal.

      Returns void

onCreate?: ((value?: T) => void)

A function called at the moment the signal is created.

Type declaration

    • (value?): void
    • Parameters

      • Optionalvalue: T

        An initial value of the signal.

      Returns void

onDeactivate?: ((value: T) => void)

A function called when the last subscriber or the last active dependent signal disappears.

Type declaration

    • (value): void
    • Parameters

      • value: T

        The current value of the signal.

      Returns void

onException?: ((e: unknown, prevValue?: T) => void)

A function called whenever an unhandled exception occurs during the calculation of the signal value.

Type declaration

    • (e, prevValue?): void
    • Parameters

      • e: unknown

        An exception.

      • OptionalprevValue: T

        The previous value of the signal.

      Returns void

onUpdate?: ((value: T, prevValue?: T) => void)

A function called each time the signal value is updated.

Type declaration

    • (value, prevValue?): void
    • Parameters

      • value: T

        The new value of the signal.

      • OptionalprevValue: T

        The previous value of the signal.

      Returns void