UNPKG

1.58 kBTypeScriptView Raw
1import type { Atom, Getter, WritableAtom } from 'jotai/vanilla';
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};
29type OptionsWithInitialValue<Data> = {
30 initialValue: Data | (() => Data);
31 unstable_timeout?: number;
32};
33export declare function atomWithObservable<Data>(getObservable: (get: Getter) => SubjectLike<Data>, options: OptionsWithInitialValue<Data>): WritableAtom<Data, [Data], void>;
34export declare function atomWithObservable<Data>(getObservable: (get: Getter) => SubjectLike<Data>, options?: Options<Data>): WritableAtom<Data | Promise<Data>, [Data], void>;
35export declare function atomWithObservable<Data>(getObservable: (get: Getter) => ObservableLike<Data>, options: OptionsWithInitialValue<Data>): Atom<Data>;
36export declare function atomWithObservable<Data>(getObservable: (get: Getter) => ObservableLike<Data>, options?: Options<Data>): Atom<Data | Promise<Data>>;
37export {};
38
\No newline at end of file