Skip to main content

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

const name = atom('name', 'John')

console.log(name.value) // 'John'

Type parameters

  • Value
  • Diff = unknown

Hierarchy

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.

Inherited from: Signal.name

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.

Inherited from: Signal.value

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

NameType
epochnumber

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

NameTypeDescription
valueValueThe new value to set.
diff?DiffThe 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

NameTypeDescription
updater(value: Value) => ValueA function that takes the current value and returns the new value.

Returns

Value

Defined in: signia/src/Atom.ts:65