esoftplay 0.0.136-h → 0.0.136-j
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/global.ts +27 -11
- package/mmkv.d.ts +2 -0
- package/mmkv.ts +20 -0
- package/package.json +1 -1
package/global.ts
CHANGED
|
@@ -17,18 +17,31 @@ export interface useGlobalAutoSync {
|
|
|
17
17
|
post: (item: any) => Object,
|
|
18
18
|
isSyncing?: (isSync: boolean) => void
|
|
19
19
|
}
|
|
20
|
+
interface useGlobalOptionA {
|
|
21
|
+
persistKey?: string;
|
|
22
|
+
inFastStorage?: boolean;
|
|
23
|
+
inFile?: never; // Ensures inFile is not present in useGlobalOptionA
|
|
24
|
+
listener?: (data: any) => void;
|
|
25
|
+
useAutoSync?: useGlobalAutoSync;
|
|
26
|
+
jsonBeautify?: boolean;
|
|
27
|
+
isUserData?: boolean;
|
|
28
|
+
loadOnInit?: boolean;
|
|
29
|
+
onFinish?: () => void;
|
|
30
|
+
}
|
|
20
31
|
|
|
21
|
-
|
|
22
|
-
persistKey?: string
|
|
23
|
-
inFile?: boolean
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
interface useGlobalOptionB {
|
|
33
|
+
persistKey?: string;
|
|
34
|
+
inFile?: boolean;
|
|
35
|
+
inFastStorage?: never; // Ensures inFastStorage is not present in useGlobalOptionB
|
|
36
|
+
listener?: (data: any) => void;
|
|
37
|
+
useAutoSync?: useGlobalAutoSync;
|
|
38
|
+
jsonBeautify?: boolean;
|
|
39
|
+
isUserData?: boolean;
|
|
40
|
+
loadOnInit?: boolean;
|
|
41
|
+
onFinish?: () => void;
|
|
30
42
|
}
|
|
31
43
|
|
|
44
|
+
export type useGlobalOption = useGlobalOptionA | useGlobalOptionB;
|
|
32
45
|
export interface useGlobalConnect<T> {
|
|
33
46
|
render: (props: T) => any,
|
|
34
47
|
}
|
|
@@ -44,7 +57,10 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
|
|
|
44
57
|
let sync: any = undefined
|
|
45
58
|
|
|
46
59
|
if (o?.persistKey) {
|
|
47
|
-
|
|
60
|
+
if (o?.inFastStorage == true) {
|
|
61
|
+
STORAGE = require('esoftplay/mmkv').default
|
|
62
|
+
} else
|
|
63
|
+
STORAGE = o?.inFile ? (require('esoftplay/storage').default) : (require('@react-native-async-storage/async-storage').default)
|
|
48
64
|
loaded = 0
|
|
49
65
|
if (o?.loadOnInit)
|
|
50
66
|
loadFromDisk()
|
|
@@ -166,7 +182,7 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
|
|
|
166
182
|
set(initValue)
|
|
167
183
|
}
|
|
168
184
|
|
|
169
|
-
function useSelector(se: (state: T) => any): void {
|
|
185
|
+
async function useSelector(se: (state: T) => any): void {
|
|
170
186
|
loadFromDisk()
|
|
171
187
|
|
|
172
188
|
let [l, s] = R.useState<any>(se(value));
|
package/mmkv.d.ts
ADDED
package/mmkv.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { MMKV } from 'react-native-mmkv';
|
|
2
|
+
|
|
3
|
+
const storage = new MMKV()
|
|
4
|
+
|
|
5
|
+
const FastStorage = {
|
|
6
|
+
getItem(key: string): Promise<string | undefined | null> {
|
|
7
|
+
return new Promise((r) => r(storage.getString(key)))
|
|
8
|
+
},
|
|
9
|
+
setItem(key: string, value: string) {
|
|
10
|
+
storage.set(key, value)
|
|
11
|
+
},
|
|
12
|
+
async removeItem(key: string) {
|
|
13
|
+
storage.delete(key)
|
|
14
|
+
},
|
|
15
|
+
clear(): void {
|
|
16
|
+
storage.clearAll()
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default FastStorage;
|