-
-
Notifications
You must be signed in to change notification settings - Fork 190
/
persist.tsx
90 lines (76 loc) · 1.48 KB
/
persist.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import * as React from 'react';
import { createTransform, persist, useStoreRehydrated } from 'easy-peasy';
persist({
foo: 'bar',
});
const model = persist(
{
foo: 'bar',
},
{
allow: ['foo'],
deny: ['foo'],
mergeStrategy: 'mergeShallow',
storage: 'sessionStorage',
transformers: [
{
in: (data, key) => `${key}foo`,
out: (data, key) => `${key}foo`,
},
],
},
);
`${model.foo}baz`;
persist(
{
foo: 'bar',
},
{
migrations: {
migrationVersion: 1,
1: (state) => {
state.foo = 'bar';
delete state.migrationConflict
}
},
},
);
createTransform(
(data, key) => `${key}foo`,
(data, key) => `${key}foo`,
{
whitelist: ['foo'],
blacklist: ['foo'],
},
);
createTransform(
(data, key) => `${key}foo`,
(data, key) => `${key}foo`,
);
createTransform((data, key, fullState) => `${key}foo`);
createTransform(undefined, (data, key) => `${key}foo`, {
whitelist: ['foo'],
blacklist: ['foo'],
});
createTransform(undefined, undefined, {
whitelist: ['foo'],
blacklist: ['foo'],
});
const transformer = createTransform(
(data, key) => `${key}foo`,
(data, key) => `${key}foo`,
{
whitelist: ['foo'],
blacklist: ['foo'],
},
);
if (transformer.in) {
transformer.in('foo', 'bar');
}
if (transformer.out) {
transformer.out('foo', 'bar');
}
function App() {
const rehydrated = useStoreRehydrated();
return rehydrated ? <div>Loaded</div> : <div>Loading...</div>;
}