ComputedOptions
See source codeTable of contents
Options for configuring computed signals. Used when calling computed or using the @computed decorator.
interface ComputedOptions<Value, Diff> {}Example
const greeting = computed('greeting', () => `Hello ${name.get()}!`, {
historyLength: 10,
isEqual: (a, b) => a === b,
computeDiff: (oldVal, newVal) => ({
type: 'change',
from: oldVal,
to: newVal,
}),
})Properties
computeDiff
A method used to compute a diff between the computed's old and new values. If provided, it will not be used unless you also specify ComputedOptions.historyLength.
computeDiff?: ComputeDiff<Value, Diff>historyLength
The maximum number of diffs to keep in the history buffer.
If you don't need to compute diffs, or if you will supply diffs manually via Atom.set, you can leave this as undefined and no history buffer will be created.
If you expect the value to be part of an active effect subscription all the time, and to not change multiple times inside of a single transaction, you can set this to a relatively low number (e.g. 10).
Otherwise, set this to a higher number based on your usage pattern and memory constraints.
historyLength?: numberMethods
isEqual
If provided, this will be used to compare the old and new values of the computed to determine if the value has changed.
By default, values are compared using first using strict equality (===), then Object.is, and finally any .equals method present in the object's prototype chain.
Parameters
| Name | Description |
|---|---|
| The old value |
| The new value |
Returns
booleanTrue if the values are equal, false otherwise.