• Lifts methods from the signal's value to the signal itself.

    Type Parameters

    • T extends {}

      the type of the signal's value as well as the type where the functions are lifted from.

    • const U extends undefined | null | readonly UpdaterKey<T>[]

      A tuple that contains the names of methods appropriate for updating.

    • const M extends undefined | null | readonly MethodKey<T>[] = null

      A tuple that contains the names of methods appropriate for mutating.

    Parameters

    • valueSource: Exclude<T, Signal<unknown>> | WritableSignal<T>

      Either a value or a Writable signal.

    • updaters: U

      A tuple that contains the names that will return a new value.

    • Optionalmutators: M

      A tuple that contains the names that will modify the signal's value directly. To guarantee this will return a new value, structuredClone or object.assign is used to create a brand new object, so use with caution.

    • Optionaloptions: LiftSignalOptions<T>

    Returns WritableSignal<T> & BoundMethods<T, NonNullable<M>> & BoundMethods<T, NonNullable<U>>

    const awesomeArray = liftSignal([1, 2, 3, 4], ['filter'], ['push', 'pop']);
    awesomeArray.push(5);
    console.log(awesomeArray()); //[1, 2, 3, 4, 5];
    awesomeArray.pop();
    console.log(awesomeArray()); //[1, 2, 3, 4];
    awesomeArray.filter(x => x % 2 === 0);
    console.log(awesomeArray()); //[2, 4];