Creates a WriteableSignal similar to array.reduce: Every time a value is set, callbackFn is run with the previous value to create a new value.
The signal's initial value
The callback run when the signal is set that will create its value
The equality function that will run after callbackFn
A writable signal whose output value is run through the callbackFn.
const accumulateValue = reduceSignal(1, (prior, cur) => prior + cur);console.log(accumulateValue()); // 1accumulateValue.set(5);console.log(accumulateValue()); // 6accumulateValue.update(x => x + 1);console.log(accumulateValue()); // 13 Copy
const accumulateValue = reduceSignal(1, (prior, cur) => prior + cur);console.log(accumulateValue()); // 1accumulateValue.set(5);console.log(accumulateValue()); // 6accumulateValue.update(x => x + 1);console.log(accumulateValue()); // 13
Optional
Creates a WriteableSignal similar to array.reduce: Every time a value is set, callbackFn is run with the previous value to create a new value.
Param: initialValue
The signal's initial value
Param: callbackFn
The callback run when the signal is set that will create its value
Param: options
The equality function that will run after callbackFn
Returns
A writable signal whose output value is run through the callbackFn.
Example