UNPKG

1.09 kBTypeScriptView Raw
1import type { Atom, Getter, WritableAtom } from 'jotai';
2type AnyError = unknown;
3declare global {
4 interface SymbolConstructor {
5 readonly observable: symbol;
6 }
7}
8type Subscription = {
9 unsubscribe: () => void;
10};
11type Observer<T> = {
12 next: (value: T) => void;
13 error: (error: AnyError) => void;
14 complete: () => void;
15};
16type ObservableLike<T> = {
17 [Symbol.observable]?: () => ObservableLike<T> | undefined;
18} & ({
19 subscribe(observer: Partial<Observer<T>>): Subscription;
20} | {
21 subscribe(observer: Partial<Observer<T>>): Subscription;
22 subscribe(next: (value: T) => void): Subscription;
23});
24type SubjectLike<T> = ObservableLike<T> & Observer<T>;
25type Options<Data> = {
26 initialValue?: Data | (() => Data);
27 unstable_timeout?: number;
28};
29export declare function atomWithObservable<Data>(getObservable: (get: Getter) => SubjectLike<Data>, options?: Options<Data>): WritableAtom<Data, Data>;
30export declare function atomWithObservable<Data>(getObservable: (get: Getter) => ObservableLike<Data>, options?: Options<Data>): Atom<Data>;
31export {};
32
\No newline at end of file