Open yw662 opened 1 month ago
Computed signals may depend on not only the current values of other signals, but also the previous value of itself. Eg.
const currentMsg = new Signal.State({ sender: 'foo', msg:'bar' }) const chatHistory = new Signal.Computed(prev => [...prev ?? [], currentMsg.get()])
It may also use a change list to reduce calculation:
const a = new Signal.State... const b = new Signal.State... const computed = new Signal.Computed((prev, changes) => ({...prev, ...changes.includes(a) ? ... :{}, ...changes.includes(b) ? ... :{}))
And a diff of the changes:
const a = new Signal.State([1, 2, 3]) const computed = new Singal.Computed((prev, changes, {a:diff_a}) => prev ? applyDiff(prev, diff_a) : a.map(...))
In Solid, effects and computeds have an argument to use the last returned value. related https://github.com/tc39/proposal-signals/issues/92 (signal setter using previous value)
Computed signals may depend on not only the current values of other signals, but also the previous value of itself. Eg.
It may also use a change list to reduce calculation:
And a diff of the changes: