esoftplay 0.0.133-u → 0.0.133-w
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/bin/build.js +1 -0
- package/global.ts +10 -3
- package/modules/lib/lazy.tsx +48 -8
- package/package.json +1 -1
package/bin/build.js
CHANGED
|
@@ -357,6 +357,7 @@ export default UserIndex`;
|
|
|
357
357
|
if (installExpoLibs.length > 0)
|
|
358
358
|
cmd += "&& expo install " + installExpoLibs.join(" ")
|
|
359
359
|
execSync(cmd + "|| true")
|
|
360
|
+
execSync("cd ../../ && bun install || true")
|
|
360
361
|
execSync("cd ../../ && bun ./node_modules/esoftplay/bin/router.js || true")
|
|
361
362
|
execSync("cd ../../ && bun ./node_modules/esoftplay/bin/locale.js || true")
|
|
362
363
|
console.log('App.js has been replace to App.tsx');
|
package/global.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import esp from 'esoftplay/esp';
|
|
2
2
|
import * as R from 'react';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
4
|
export interface useGlobalReturn<T> {
|
|
7
5
|
useState: () => [T, (newState: T | ((newState: T) => T)) => void, () => T],
|
|
8
6
|
get: (param?: string, ...params: string[]) => T,
|
|
9
7
|
set: (x: T | ((old: T) => T)) => void,
|
|
10
8
|
reset: () => void,
|
|
9
|
+
listen: (cb: (value: T) => void) => () => void
|
|
11
10
|
sync: () => void,
|
|
12
11
|
connect: (props: useGlobalConnect<T>) => any,
|
|
13
12
|
useSelector: (selector: (state: T) => any) => any;
|
|
@@ -40,6 +39,7 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
|
|
|
40
39
|
const isEqual = require('react-fast-compare');
|
|
41
40
|
const subsSetter = new Set<Function>()
|
|
42
41
|
let value: T = initValue;
|
|
42
|
+
let listener = new Set<Function>()
|
|
43
43
|
let loaded = -1
|
|
44
44
|
let sync: any = undefined
|
|
45
45
|
|
|
@@ -111,6 +111,10 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
function listen(cb: (value: T) => void): () => void {
|
|
115
|
+
listener.add(cb)
|
|
116
|
+
return () => listener.delete(cb)
|
|
117
|
+
}
|
|
114
118
|
|
|
115
119
|
/* register to userData to automatically reset state and persist */
|
|
116
120
|
if (o?.isUserData) {
|
|
@@ -148,6 +152,9 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
|
|
|
148
152
|
o.listener(newValue)
|
|
149
153
|
if (o?.useAutoSync && sync)
|
|
150
154
|
sync?.(newValue.filter((item: any) => item.synced != 1))
|
|
155
|
+
if (listener.size > 0) {
|
|
156
|
+
listener.forEach((fun) => fun?.(newValue))
|
|
157
|
+
}
|
|
151
158
|
}
|
|
152
159
|
};
|
|
153
160
|
|
|
@@ -214,5 +221,5 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
|
|
|
214
221
|
return children ? R.cloneElement(children) : null
|
|
215
222
|
}
|
|
216
223
|
|
|
217
|
-
return { useState, get, set, useSelector, reset: del, connect: _connect, sync: _sync };
|
|
224
|
+
return { useState, get, set, useSelector, reset: del, connect: _connect, sync: _sync, listen: listen };
|
|
218
225
|
}
|
package/modules/lib/lazy.tsx
CHANGED
|
@@ -1,24 +1,64 @@
|
|
|
1
1
|
// withHooks
|
|
2
2
|
// noPage
|
|
3
|
-
|
|
4
|
-
import {
|
|
3
|
+
|
|
4
|
+
import { UseTasks } from 'esoftplay/cache/use/tasks/import';
|
|
5
|
+
import useGlobalState from 'esoftplay/global';
|
|
6
|
+
import useSafeState from 'esoftplay/state';
|
|
7
|
+
import { startTransition, useEffect } from 'react';
|
|
5
8
|
import { InteractionManager } from 'react-native';
|
|
6
9
|
|
|
7
10
|
export interface LibLazyProps {
|
|
8
11
|
children?: any;
|
|
9
12
|
}
|
|
10
13
|
|
|
14
|
+
const renderList = useGlobalState<Function[]>([])
|
|
15
|
+
const useTasks = UseTasks<Function>()
|
|
16
|
+
|
|
17
|
+
let timeoutId: NodeJS.Timeout;
|
|
18
|
+
function debounce(cb: () => void, delay: number) {
|
|
19
|
+
clearTimeout(timeoutId);
|
|
20
|
+
timeoutId = setTimeout(function () {
|
|
21
|
+
cb()
|
|
22
|
+
}, delay);
|
|
23
|
+
}
|
|
24
|
+
let timeoutIdB: NodeJS.Timeout;
|
|
25
|
+
function debounceB(cb: () => void, delay: number) {
|
|
26
|
+
clearTimeout(timeoutIdB);
|
|
27
|
+
timeoutIdB = setTimeout(function () {
|
|
28
|
+
cb()
|
|
29
|
+
}, delay);
|
|
30
|
+
}
|
|
31
|
+
|
|
11
32
|
export default function m(props: LibLazyProps): any {
|
|
12
33
|
const [done, setDone] = useSafeState(false);
|
|
34
|
+
const [sync] = useTasks((item) => new Promise((next) => {
|
|
35
|
+
InteractionManager.runAfterInteractions(() => {
|
|
36
|
+
startTransition(() => {
|
|
37
|
+
item(true)
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
next()
|
|
40
|
+
}, 50);
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
}))
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (done) {
|
|
47
|
+
debounceB(() => {
|
|
48
|
+
sync(renderList.get())
|
|
49
|
+
}, 100);
|
|
50
|
+
}
|
|
51
|
+
}, [done])
|
|
13
52
|
|
|
14
53
|
useEffect(() => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
54
|
+
renderList.set((x) => [...x, setDone])
|
|
55
|
+
debounce(() => {
|
|
56
|
+
sync(renderList.get())
|
|
57
|
+
}, 100);
|
|
18
58
|
return () => {
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
}, [])
|
|
59
|
+
renderList.set((x) => x.filter((c) => c !== setDone))
|
|
60
|
+
}
|
|
61
|
+
}, [])
|
|
22
62
|
|
|
23
63
|
return done ? props.children ?? null : null;
|
|
24
64
|
}
|