esoftplay 0.0.127-c → 0.0.127-e
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 +10 -2
- package/modules/lib/global.tsx +30 -0
- package/package.json +1 -1
package/global.ts
CHANGED
|
@@ -20,7 +20,8 @@ export interface useGlobalOption {
|
|
|
20
20
|
inFile?: boolean,
|
|
21
21
|
listener?: (data: any) => void,
|
|
22
22
|
jsonBeautify?: boolean,
|
|
23
|
-
isUserData?: boolean
|
|
23
|
+
isUserData?: boolean,
|
|
24
|
+
onFinish?: () => void
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
export interface useGlobalConnect<T> {
|
|
@@ -37,8 +38,8 @@ const Context = {
|
|
|
37
38
|
this.idx = 0
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
|
-
|
|
41
41
|
export const globalIdx = Context
|
|
42
|
+
let timeoutFinish: NodeJS.Timeout
|
|
42
43
|
export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): useGlobalReturn<T> {
|
|
43
44
|
const STORAGE = o?.inFile ? Storage : AsyncStorage
|
|
44
45
|
const _idx = o?.persistKey || globalIdx.idx
|
|
@@ -62,9 +63,16 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
|
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
}
|
|
66
|
+
if (o?.onFinish) {
|
|
67
|
+
clearTimeout(timeoutFinish)
|
|
68
|
+
timeoutFinish = setTimeout(() => {
|
|
69
|
+
o.onFinish?.()
|
|
70
|
+
}, 50);
|
|
71
|
+
}
|
|
65
72
|
})
|
|
66
73
|
}
|
|
67
74
|
|
|
75
|
+
|
|
68
76
|
/* register to userData to automatically reset state and persist */
|
|
69
77
|
if (o?.isUserData) {
|
|
70
78
|
function resetFunction() {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// withHooks
|
|
2
|
+
// noPage
|
|
3
|
+
|
|
4
|
+
import { LibLoading } from 'esoftplay/cache/lib/loading/import';
|
|
5
|
+
import useGlobalState from 'esoftplay/global';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export interface LibGlobalArgs {
|
|
10
|
+
|
|
11
|
+
}
|
|
12
|
+
export interface LibGlobalProps {
|
|
13
|
+
waitForFinish: boolean,
|
|
14
|
+
waitingView?: any,
|
|
15
|
+
children?: any
|
|
16
|
+
}
|
|
17
|
+
const globalReady = useGlobalState(false, {
|
|
18
|
+
persistKey: "globalReady",
|
|
19
|
+
onFinish: () => {
|
|
20
|
+
globalReady.set(true)
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
export default function m(props: LibGlobalProps): any {
|
|
25
|
+
const [ready] = globalReady.useState();
|
|
26
|
+
if (props.waitForFinish)
|
|
27
|
+
return ready ? props.children : props.waitingView || <LibLoading />
|
|
28
|
+
else
|
|
29
|
+
return props.children
|
|
30
|
+
}
|