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