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