UNPKG

@dhmk/atom

Version:

Lightweight mobx-like observable values, computed values and side-effects

31 lines (30 loc) 1.27 kB
import { ValueAtom } from "./atoms/value"; import { ComputedAtom } from "./atoms/computed"; import { EffectAtom } from "./atoms/effect"; import { runtime } from "./runtime"; import { AtomOptions, EffectAtomOptions } from "./types"; import observable from "./observable"; import observableObject, { as } from "./observable/object"; import observableArray from "./observable/array"; type EffectState = { (): void; isInitial: boolean; invalidate(): void; }; declare function observe(fn: (state: EffectState) => void, opts?: EffectAtomOptions): EffectState; type Atom<T> = { get(): T; }; type WritableAtom<T> = Atom<T> & { set(x: T): void; }; type AtomOptions_<T> = AtomOptions<T> & Partial<{ set(setter: (x: T) => void): (x: T) => void; }>; type ComputedOptions_<T> = AtomOptions<T>; type Getter<T> = () => T; declare function atom<T>(fn: () => T, opts?: ComputedOptions_<T>): Atom<T> & Getter<T>; declare function atom<T>(value: T, opts?: AtomOptions_<T>): WritableAtom<T> & Getter<T>; declare const act: <T>(fn: () => T) => T; declare const untracked: <T>(fn: () => T) => T; export { ValueAtom, ComputedAtom, EffectAtom, atom, act, untracked, observe, observable, observableObject, observableArray, as, runtime, };