1 | import type { WritableAtom } from 'jotai/vanilla';
|
2 | import { RESET } from './constants';
|
3 | type Unsubscribe = () => void;
|
4 | type SetStateActionWithReset<Value> = Value | typeof RESET | ((prev: Value) => Value | typeof RESET);
|
5 | export interface AsyncStorage<Value> {
|
6 | getItem: (key: string, initialValue: Value) => PromiseLike<Value>;
|
7 | setItem: (key: string, newValue: Value) => PromiseLike<void>;
|
8 | removeItem: (key: string) => PromiseLike<void>;
|
9 | subscribe?: (key: string, callback: (value: Value) => void, initialValue: Value) => Unsubscribe;
|
10 | }
|
11 | export interface SyncStorage<Value> {
|
12 | getItem: (key: string, initialValue: Value) => Value;
|
13 | setItem: (key: string, newValue: Value) => void;
|
14 | removeItem: (key: string) => void;
|
15 | subscribe?: (key: string, callback: (value: Value) => void, initialValue: Value) => Unsubscribe;
|
16 | }
|
17 | export interface AsyncStringStorage {
|
18 | getItem: (key: string) => PromiseLike<string | null>;
|
19 | setItem: (key: string, newValue: string) => PromiseLike<void>;
|
20 | removeItem: (key: string) => PromiseLike<void>;
|
21 | }
|
22 | export interface SyncStringStorage {
|
23 | getItem: (key: string) => string | null;
|
24 | setItem: (key: string, newValue: string) => void;
|
25 | removeItem: (key: string) => void;
|
26 | }
|
27 | export declare function createJSONStorage<Value>(getStringStorage: () => AsyncStringStorage): AsyncStorage<Value>;
|
28 | export declare function createJSONStorage<Value>(getStringStorage: () => SyncStringStorage): SyncStorage<Value>;
|
29 | export declare function atomWithStorage<Value>(key: string, initialValue: Value, storage: AsyncStorage<Value>, unstable_options?: {
|
30 | unstable_getOnInit?: boolean;
|
31 | }): WritableAtom<Value | Promise<Value>, [
|
32 | SetStateActionWithReset<Value | Promise<Value>>
|
33 | ], Promise<void>>;
|
34 | export declare function atomWithStorage<Value>(key: string, initialValue: Value, storage?: SyncStorage<Value>, unstable_options?: {
|
35 | unstable_getOnInit?: boolean;
|
36 | }): WritableAtom<Value, [SetStateActionWithReset<Value>], void>;
|
37 | export {};
|