UNPKG

1.64 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: Observer<T>): Subscription;
20} | {
21 subscribe(observer: Partial<Observer<T>>): Subscription;
22} | {
23 subscribe(observer: Partial<Observer<T>>): Subscription;
24 subscribe(next: (value: T) => void): Subscription;
25});
26type SubjectLike<T> = ObservableLike<T> & Observer<T>;
27type Options<Data> = {
28 initialValue?: Data | (() => Data);
29 unstable_timeout?: number;
30};
31type OptionsWithInitialValue<Data> = {
32 initialValue: Data | (() => Data);
33 unstable_timeout?: number;
34};
35export declare function atomWithObservable<Data>(getObservable: (get: Getter) => SubjectLike<Data>, options: OptionsWithInitialValue<Data>): WritableAtom<Data, [Data], void>;
36export declare function atomWithObservable<Data>(getObservable: (get: Getter) => SubjectLike<Data>, options?: Options<Data>): WritableAtom<Data | Promise<Data>, [Data], void>;
37export declare function atomWithObservable<Data>(getObservable: (get: Getter) => ObservableLike<Data>, options: OptionsWithInitialValue<Data>): Atom<Data>;
38export declare function atomWithObservable<Data>(getObservable: (get: Getter) => ObservableLike<Data>, options?: Options<Data>): Atom<Data | Promise<Data>>;
39export {};
40
\No newline at end of file