Interface: Atom<T>
API / @xmachines/play-atom / Atom
Defined in: 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
BaseAtom<T>
Type Parameters
| Type Parameter |
|---|
T |
Methods
get()
get(): T;Defined in: types.ts:59
Returns
T
Inherited from
set()
Call Signature
set(fn): void;Defined in: types.ts:119
Sets the value of the atom from the previous value.
Parameters
| Parameter | Type |
|---|---|
fn | (previous) => T |
Returns
void
Call Signature
set(value): void;Defined in: types.ts:121
Sets the value of the atom.
Parameters
| Parameter | Type |
|---|---|
value | T |
Returns
void
subscribe()
Call Signature
subscribe(observer): AtomSubscription;Defined in: types.ts:60
Parameters
| Parameter | Type |
|---|---|
observer | AtomObserver<T> |
Returns
Inherited from
Call Signature
subscribe( next, error?, complete?): AtomSubscription;Defined in: types.ts:61
Parameters
| Parameter | Type |
|---|---|
next | (value) => void |
error? | (error) => void |
complete? | () => void |