Atom<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.
Example
cosnt name = atom('name', 'John')
console.log(name.value) // 'John'
Type parameters
Value
Diff
=unknown
Hierarchy
Signal
<Value
,Diff
>.Atom
Index
Properties
Methods
Properties
lastChangedEpoch
number
The epoch when this signal's value last changed. Note tha this is not the same as when the value was last computed. A signal may recopmute it's value without changing it.
Inherited from: Signal.lastChangedEpoch
Defined in: signia/src/types.ts:36
name
string
The name of the signal. This is used at runtime for debugging and perf profiling only. It does not need to be globally unique.
Defined in: signia/src/types.ts:25
value
Readonly
Value
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.
Defined in: signia/src/types.ts:31
Methods
__unsafe__getWithoutCapture()
Returns the current value of the signal without capturing it as a dependency. Use this if you need to retrieve the signal's value in a hot loop where the performance overhead of dependency tracking is too high.
Signature
__unsafe__getWithoutCapture(): Value;
Returns
Value
Inherited from: Signal.unsafegetWithoutCapture
Defined in: signia/src/types.ts:47
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.
Signature
getDiffSince(epoch: number): typeof RESET_VALUE | Diff[];
Parameters
Name | Type |
---|---|
epoch | number |
Returns
typeof RESET_VALUE
| Diff
[]
Inherited from: Signal.getDiffSince
Defined in: signia/src/types.ts:42
set()
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.
Signature
set(value: Value, diff?: Diff): Value;
Parameters
Name | Type | Description |
---|---|---|
value | Value | The new value to set. |
diff? | Diff | The diff to use for the update. If not provided, the diff will be computed using AtomOptions.computeDiff. |
Returns
Value
Defined in: signia/src/Atom.ts:59
update()
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.
Signature
update(updater: Function): Value;
Parameters
Name | Type | Description |
---|---|---|
updater | (value : Value ) => Value | A function that takes the current value and returns the new value. |
Returns
Value
Defined in: signia/src/Atom.ts:65