Skip to content

Interface: Atom<T>

API / @xmachines/play-atom / Atom

Defined in: play-atom/src/types.ts:117

The writable atom. It holds one reactive value

A get() call inside a computed atom or inside a subscription tracks the atom as a dependency. A set() call notifies every computation and every observer that depends on the atom. set accepts a value, and it accepts a function of the previous value.

Example

import { createAtom } from "@xmachines/play-atom";
const name = createAtom("Alice");
console.log(name.get()); // "Alice"
name.set("Bob");
name.set((previous) => previous.toUpperCase()); // "BOB"

Extends

Type Parameters

Type Parameter
T

Methods

get()

get(): T;

Defined in: play-atom/src/types.ts:59

Returns

T

Inherited from

BaseAtom.get


set()

Call Signature

set(fn): void;

Defined in: play-atom/src/types.ts:119

Sets the value of the atom from the previous value.

Parameters
ParameterType
fn(previous) => T
Returns

void

Call Signature

set(value): void;

Defined in: play-atom/src/types.ts:121

Sets the value of the atom.

Parameters
ParameterType
valueT
Returns

void


subscribe()

Call Signature

subscribe(observer): AtomSubscription;

Defined in: play-atom/src/types.ts:60

Parameters
ParameterType
observerAtomObserver<T>
Returns

AtomSubscription

Inherited from

BaseAtom.subscribe

Call Signature

subscribe(
next,
error?,
complete?
): AtomSubscription;

Defined in: play-atom/src/types.ts:61

Parameters
ParameterType
next(value) => void
error?(error) => void
complete?() => void
Returns

AtomSubscription

Inherited from

BaseAtom.subscribe