1 | import type { SetStateAction, WritableAtom } from 'jotai';
|
2 | import { RESET } from './constants';
|
3 | declare type Unsubscribe = () => void;
|
4 | declare type AsyncStorage<Value> = {
|
5 | getItem: (key: string) => Promise<Value>;
|
6 | setItem: (key: string, newValue: Value) => Promise<void>;
|
7 | removeItem: (key: string) => Promise<void>;
|
8 | delayInit?: boolean;
|
9 | subscribe?: (key: string, callback: (value: Value) => void) => Unsubscribe;
|
10 | };
|
11 | declare type SyncStorage<Value> = {
|
12 | getItem: (key: string) => Value;
|
13 | setItem: (key: string, newValue: Value) => void;
|
14 | removeItem: (key: string) => void;
|
15 | delayInit?: boolean;
|
16 | subscribe?: (key: string, callback: (value: Value) => void) => Unsubscribe;
|
17 | };
|
18 | declare type AsyncStringStorage = {
|
19 | getItem: (key: string) => Promise<string | null>;
|
20 | setItem: (key: string, newValue: string) => Promise<void>;
|
21 | removeItem: (key: string) => Promise<void>;
|
22 | };
|
23 | declare type SyncStringStorage = {
|
24 | getItem: (key: string) => string | null;
|
25 | setItem: (key: string, newValue: string) => void;
|
26 | removeItem: (key: string) => void;
|
27 | };
|
28 | export declare function createJSONStorage<Value>(getStringStorage: () => AsyncStringStorage): AsyncStorage<Value>;
|
29 | export declare function createJSONStorage<Value>(getStringStorage: () => SyncStringStorage): SyncStorage<Value>;
|
30 | export declare function atomWithStorage<Value>(key: string, initialValue: Value, storage: AsyncStorage<Value> & {
|
31 | delayInit: true;
|
32 | }): WritableAtom<Value, SetStateAction<Value> | typeof RESET, Promise<void>>;
|
33 | export declare function atomWithStorage<Value>(key: string, initialValue: Value, storage: AsyncStorage<Value>): WritableAtom<Promise<Value>, SetStateAction<Value> | typeof RESET, Promise<void>>;
|
34 | export declare function atomWithStorage<Value>(key: string, initialValue: Value, storage: SyncStorage<Value>): WritableAtom<Value, SetStateAction<Value> | typeof RESET>;
|
35 | export declare function atomWithStorage<Value>(key: string, initialValue: Value): WritableAtom<Value, SetStateAction<Value> | typeof RESET>;
|
36 | export declare function atomWithHash<Value>(key: string, initialValue: Value, options?: {
|
37 | serialize?: (val: Value) => string;
|
38 | deserialize?: (str: string) => Value;
|
39 | delayInit?: boolean;
|
40 | replaceState?: boolean;
|
41 | subscribe?: (callback: () => void) => () => void;
|
42 | }): WritableAtom<Value, SetStateAction<Value> | typeof RESET>;
|
43 | export {};
|