withDiff
See source codeWhen writing incrementally-computed signals it is convenient (and usually more performant) to incrementally compute the diff too.
You can use this function to wrap the return value of a computed signal function to indicate that the diff should be used instead of calculating a new one with AtomOptions.computeDiff.
function withDiff<Value, Diff>(value: Value, diff: Diff): WithDiff<Value, Diff>
Example
const count = atom('count', 0)
const double = computed(
'double',
(prevValue) => {
const nextValue = count.get() * 2
if (isUninitialized(prevValue)) {
return nextValue
}
return withDiff(nextValue, nextValue - prevValue)
},
{ historyLength: 10 }
)
Parameters
Name | Description |
---|---|
|
The value. |
|
The diff. |
Returns
WithDiff<Value, Diff>
Prev
whyAmIRunningNext
track