Interface: ReadonlyAtom<T>
API / @xmachines/play-atom / ReadonlyAtom
Defined in: types.ts:97
The computed atom. It evaluates late, and it memoizes the result
createAtom returns this type for a function argument. The atom tracks each
dependency when it runs the function, and it runs the function again only after a
dependency changes. The atom therefore tracks each dependency for you, and you
manage no subscription.
Example
import { createAtom } from "@xmachines/play-atom";
const count = createAtom(0);const doubled = createAtom(() => count.get() * 2);
console.log(doubled.get()); // 0count.set(5);console.log(doubled.get()); // 10 (the atom computed it again)console.log(doubled.get()); // 10 (from the memory, with no new computation)Extends
BaseAtom<T>
Type Parameters
| Type Parameter |
|---|
T |
Methods
get()
get(): T;Defined in: types.ts:59
Returns
T
Inherited from
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 |