1 | import type { WritableAtom } from 'jotai/vanilla';
|
2 | import { RESET } from './constants';
|
3 | export declare const NO_STORAGE_VALUE: unique symbol;
|
4 | type Unsubscribe = () => void;
|
5 | type SetStateActionWithReset<Value> = Value | typeof RESET | ((prev: Value) => Value | typeof RESET);
|
6 | export interface AsyncStorage<Value> {
|
7 | getItem: (key: string) => Promise<Value | typeof NO_STORAGE_VALUE>;
|
8 | setItem: (key: string, newValue: Value) => Promise<void>;
|
9 | removeItem: (key: string) => Promise<void>;
|
10 | subscribe?: (key: string, callback: (value: Value) => void) => Unsubscribe;
|
11 | }
|
12 | export interface SyncStorage<Value> {
|
13 | getItem: (key: string) => Value | typeof NO_STORAGE_VALUE;
|
14 | setItem: (key: string, newValue: Value) => void;
|
15 | removeItem: (key: string) => void;
|
16 | subscribe?: (key: string, callback: (value: Value) => void) => Unsubscribe;
|
17 | }
|
18 | export interface AsyncStringStorage {
|
19 | getItem: (key: string) => Promise<string | null>;
|
20 | setItem: (key: string, newValue: string) => Promise<void>;
|
21 | removeItem: (key: string) => Promise<void>;
|
22 | }
|
23 | export interface 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?: SyncStorage<Value> | AsyncStorage<Value>): WritableAtom<Value, [SetStateActionWithReset<Value>], void>;
|
31 | export {};
|