Atom
See source codeTable of contents
Extends Signal<Value, Diff>.
An Atom is a signal that can be updated directly by calling Atom.set or Atom.update.
Atoms are created using the atom function.
interface Atom<Value, Diff = unknown> extends Signal<Value, Diff> {}Example
const name = atom('name', 'John')
print(name.get()) // 'John'Properties
lastChangedEpoch
The epoch when this signal's value last changed. Note that this is not the same as when the value was last computed. A signal may recompute it's value without changing it.
lastChangedEpoch: numbername
The name of the signal. This is used at runtime for debugging and perf profiling only. It does not need to be globally unique.
name: stringMethods
get
The current value of the signal. This is a reactive value, and will update when the signal changes. Any computed signal that depends on this signal will be lazily recomputed if this signal changes. Any effect that depends on this signal will be rescheduled if this signal changes.
getDiffSince
Returns the sequence of diffs between the the value at the given epoch and the current value.
Returns the RESET_VALUE constant if there is not enough information to compute the diff sequence.
Parameters
| Name | Description |
|---|---|
| The epoch to get diffs since. |
Returns
Diff[] | RESET_VALUEset
Sets the value of this atom to the given value. If the value is the same as the current value, this is a no-op.
Parameters
| Name | Description |
|---|---|
| The new value to set. |
| The diff to use for the update. If not provided, the diff will be computed using AtomOptions.computeDiff. |
Returns
Valueupdate
Updates the value of this atom using the given updater function. If the returned value is the same as the current value, this is a no-op.
Parameters
| Name | Description |
|---|---|
| A function that takes the current value and returns the new value. |
Returns
Value