Documentation - v0.0.1
    Preparing search index...

    Interface Signal<T>

    A reactive signal that holds a value of type T and allows for dependency tracking and updates.

    interface Signal<T> {
        cleanup?: CleanupFn;
        get: () => T;
        registerDependency: (listener: (newValue: T) => void) => CleanupFn;
        set: (newValue: T) => void;
        unregisterAllDependencies: () => void;
        update: (cb: (oldValue: T) => T) => void;
    }

    Type Parameters

    • T
    Index

    Properties

    cleanup?: CleanupFn

    Optional cleanup function to be called when the signal is no longer needed.

    get: () => T

    Retrieves the current value of the signal.

    registerDependency: (listener: (newValue: T) => void) => CleanupFn

    Registers a dependency listener that will be called whenever the signal value changes. Returns a function to unregister the listener.

    set: (newValue: T) => void

    Sets the signal to a new value, updating all registered dependencies.

    unregisterAllDependencies: () => void

    Unregisters all previously registered dependency listeners.

    update: (cb: (oldValue: T) => T) => void

    Updates the signal value using a callback that receives the old value and returns the new value.