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