Table 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

from Signal

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.

lastChangedEpoch: number

name

from Signal

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: string

Methods


get

from Signal

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

from Signal

Returns the sequence of diffs between the the value at the given epoch and the current value. Returns the constant if there is not enough information to compute the diff sequence.

Parameters

NameDescription

epoch

number

The epoch to get diffs since.

Returns

Diff[] | RESET_VALUE

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.

Parameters

NameDescription

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

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.

Parameters

NameDescription

updater

(value: Value) => Value

A function that takes the current value and returns the new value.

Returns

Value

Prev
TLUserPreferences
Next
AtomOptions

We use cookies on this website.
Learn more in our Cookie Policy.