1 | /**
|
2 | * Options to be used to construct a {@link VuexPersistence} object
|
3 | */
|
4 | import { Payload } from 'vuex';
|
5 | import { AsyncStorage } from './AsyncStorage';
|
6 | import { MergeOptionType } from './utils';
|
7 | export interface PersistOptions<S> {
|
8 | /**
|
9 | * Window.Storage type object. Default is localStorage
|
10 | */
|
11 | storage?: Storage | AsyncStorage;
|
12 | /**
|
13 | * Method to retrieve state from persistence
|
14 | * @param key
|
15 | * @param [storage]
|
16 | */
|
17 | restoreState?: (key: string, storage?: Storage) => Promise<S> | S;
|
18 | /**
|
19 | * Method to save state into persistence
|
20 | * @param key
|
21 | * @param state
|
22 | * @param [storage]
|
23 | */
|
24 | saveState?: (key: string, state: {}, storage?: Storage) => Promise<void> | void;
|
25 | /**
|
26 | * Function to reduce state to the object you want to save.
|
27 | * Be default, we save the entire state.
|
28 | * You can use this if you want to save only a portion of it.
|
29 | * @param state
|
30 | */
|
31 | reducer?: (state: S) => {};
|
32 | /**
|
33 | * Key to use to save the state into the storage
|
34 | */
|
35 | key?: string;
|
36 | /**
|
37 | * Method to filter which mutations will trigger state saving
|
38 | * Be default returns true for all mutations.
|
39 | * Check mutations using <code>mutation.type</code>
|
40 | * @param mutation object of type {@link Payload}
|
41 | */
|
42 | filter?: (mutation: Payload) => boolean;
|
43 | /**
|
44 | * Names of modules that you want to persist.
|
45 | * If you create your custom {@link PersistOptions.reducer} function,
|
46 | * then that will override filter behaviour, not this argument
|
47 | */
|
48 | modules?: string[];
|
49 | /**
|
50 | * Set this to true to support
|
51 | * <a href="https://vuex.vuejs.org/en/strict.html">Vuex Strict Mode</a>
|
52 | * @default false
|
53 | */
|
54 | strictMode?: boolean;
|
55 | /**
|
56 | * If your storage is async
|
57 | * i.e., if setItem(), getItem() etc return Promises
|
58 | * (Must be used for asynchronous storages like LocalForage)
|
59 | * @default false
|
60 | */
|
61 | asyncStorage?: boolean;
|
62 | /**
|
63 | * Support serializing circular json objects
|
64 | * <pre>
|
65 | * let x = {a: 10}
|
66 | * x.b = x
|
67 | * console.log(x.a) // 10
|
68 | * console.log(x.b.a) // 10
|
69 | * console.log(x.b.b.a) // 10
|
70 | * </pre>
|
71 | * @default false
|
72 | *
|
73 | */
|
74 | supportCircular?: boolean;
|
75 | /**
|
76 | * Whether to replace or concat arrays when merging
|
77 | * saved state with restored state
|
78 | * defaults to replacing arrays
|
79 | */
|
80 | mergeOption?: MergeOptionType;
|
81 | }
|