WithDiff
Interface
Table of contents
Interface representing a value wrapped with its corresponding diff. Used in incremental computation to provide both the new value and the diff from the previous value.
interface WithDiff<Value, Diff> {}Properties
diff
The diff between the previous and current value.
diff: Diff;value
The computed value.
value: Value;Value
A singleton class used to wrap computed signal values along with their diffs. This class is used internally by the withDiff function to provide both the computed value and its diff to the signal system.
WithDiff: {
new <Value, Diff>(
value: Value,
diff: Diff,
): {
diff: Diff;
value: Value;
};
};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);
});Prev
UNINITIALIZEDNext
MigrationFailureReason