esoftplay 0.0.136-g → 0.0.136-i

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 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
- export interface useGlobalOption {
22
- persistKey?: string,
23
- inFile?: boolean,
24
- listener?: (data: any) => void,
25
- useAutoSync?: useGlobalAutoSync,
26
- jsonBeautify?: boolean,
27
- isUserData?: boolean,
28
- loadOnInit?: boolean,
29
- onFinish?: () => void
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
- STORAGE = o?.inFile ? (require('esoftplay/storage').default) : (require('@react-native-async-storage/async-storage').default)
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()
@@ -82,33 +98,32 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
82
98
  })[0]
83
99
  }
84
100
 
85
- function loadFromDisk() {
101
+ async function loadFromDisk() {
86
102
  if (loaded == 0) {
87
103
  loaded = 1
88
104
  let persistKey = o?.persistKey
89
- STORAGE.getItem(String(persistKey)).then((p: any) => {
90
- if (p) {
91
- if (persistKey != '__globalReady')
92
- if (p != undefined && typeof p == 'string' && (p.startsWith("{") || p.startsWith("[")))
93
- try { set(JSON.parse(p)) } catch (error) { }
94
- else {
95
- if (p == "true" || p == "false") {
96
- try { /* @ts-ignore */ set(eval(p)) } catch (error) { }
97
- } else if (isNaN(p)) {
98
- try { /* @ts-ignore */ set(p) } catch (error) { }
99
- } else {
100
- try { /* @ts-ignore */ set(eval(p)) } catch (error) { }
101
- }
105
+ const p = await STORAGE.getItem(String(persistKey))
106
+ if (p) {
107
+ if (persistKey != '__globalReady')
108
+ if (p != undefined && typeof p == 'string' && (p.startsWith("{") || p.startsWith("[")))
109
+ try { set(JSON.parse(p)) } catch (error) { }
110
+ else {
111
+ if (p == "true" || p == "false") {
112
+ try { /* @ts-ignore */ set(eval(p)) } catch (error) { }
113
+ } else if (isNaN(p)) {
114
+ try { /* @ts-ignore */ set(p) } catch (error) { }
115
+ } else {
116
+ try { /* @ts-ignore */ set(eval(p)) } catch (error) { }
102
117
  }
103
- }
104
- if (o?.onFinish) {
118
+ }
119
+ }
120
+ if (o?.onFinish) {
121
+ clearTimeout(timeoutFinish)
122
+ timeoutFinish = setTimeout(() => {
123
+ o.onFinish?.()
105
124
  clearTimeout(timeoutFinish)
106
- timeoutFinish = setTimeout(() => {
107
- o.onFinish?.()
108
- clearTimeout(timeoutFinish)
109
- }, 50);
110
- }
111
- })
125
+ }, 50);
126
+ }
112
127
  }
113
128
  }
114
129
 
@@ -166,7 +181,7 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
166
181
  set(initValue)
167
182
  }
168
183
 
169
- function useSelector(se: (state: T) => any): void {
184
+ async function useSelector(se: (state: T) => any): void {
170
185
  loadFromDisk()
171
186
 
172
187
  let [l, s] = R.useState<any>(se(value));
package/mmkv.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import FastStorage from "./mmkv";
2
+ export default FastStorage
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): string | undefined {
7
+ return 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;
@@ -1,67 +1,73 @@
1
1
  // withHooks
2
2
  // noPage
3
3
 
4
- import { UseTasks } from 'esoftplay/cache/use/tasks/import';
5
- import useGlobalState from 'esoftplay/global';
6
4
  import useSafeState from 'esoftplay/state';
7
- import { startTransition, useEffect } from 'react';
5
+ import { useEffect } from 'react';
8
6
  import { InteractionManager } from 'react-native';
9
7
 
10
8
  export interface LibLazyProps {
11
9
  children?: any;
12
10
  }
13
11
 
14
- const renderList = useGlobalState<Function[]>([])
15
- const useTasks = UseTasks<Function>()
12
+ // const renderList = useGlobalState<Function[]>([])
13
+ // const useTasks = UseTasks<Function>()
16
14
 
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
- }
15
+ // let timeoutId: NodeJS.Timeout;
16
+ // function debounce(cb: () => void, delay: number) {
17
+ // clearTimeout(timeoutId);
18
+ // timeoutId = setTimeout(function () {
19
+ // cb()
20
+ // }, delay);
21
+ // }
22
+ // let timeoutIdB: NodeJS.Timeout;
23
+ // function debounceB(cb: () => void, delay: number) {
24
+ // clearTimeout(timeoutIdB);
25
+ // timeoutIdB = setTimeout(function () {
26
+ // cb()
27
+ // }, delay);
28
+ // }
31
29
 
32
30
  export default function m(props: LibLazyProps): any {
33
31
  const [done, setDone] = useSafeState(false);
34
- const [sync] = useTasks((item) => new Promise((next) => {
35
- InteractionManager.runAfterInteractions(() => {
36
- startTransition(() => {
37
- item(true)
38
- const timer = setTimeout(() => {
39
- next()
40
- clearTimeout(timer)
41
- }, 50);
42
- })
43
- })
44
- }))
45
-
46
- useEffect(() => {
47
- if (done) {
48
- debounceB(() => {
49
- sync(renderList.get())
50
- }, 100);
51
- }
52
- }, [done])
53
32
 
54
33
  useEffect(() => {
55
- renderList.set((x) => [...x, setDone])
56
- debounce(() => {
57
- sync(renderList.get())
58
- }, 100);
59
- return () => {
60
- renderList.set((x) => x.filter((c) => c !== setDone))
61
- }
34
+ const int = InteractionManager.runAfterInteractions(() => {
35
+ setDone(true)
36
+ })
37
+ return () => int.cancel()
62
38
  }, [])
63
39
 
64
- return done ? props.children ?? null : null;
40
+ // const [sync] = useTasks((item) => new Promise((next) => {
41
+ // InteractionManager.runAfterInteractions(() => {
42
+ // startTransition(() => {
43
+ // item(true)
44
+ // const timer = setTimeout(() => {
45
+ // next()
46
+ // clearTimeout(timer)
47
+ // }, 50);
48
+ // })
49
+ // })
50
+ // }))
51
+
52
+ // useEffect(() => {
53
+ // if (done) {
54
+ // debounceB(() => {
55
+ // sync(renderList.get())
56
+ // }, 100);
57
+ // }
58
+ // }, [done])
59
+
60
+ // useEffect(() => {
61
+ // renderList.set((x) => [...x, setDone])
62
+ // debounce(() => {
63
+ // sync(renderList.get())
64
+ // }, 100);
65
+ // return () => {
66
+ // renderList.set((x) => x.filter((c) => c !== setDone))
67
+ // }
68
+ // }, [])
69
+
70
+ return done ? (props.children ?? null) : null;
65
71
  }
66
72
 
67
73
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esoftplay",
3
- "version": "0.0.136-g",
3
+ "version": "0.0.136-i",
4
4
  "description": "embedding data from esoftplay framework (web based) into mobile app",
5
5
  "main": "cache/index.js",
6
6
  "types": "../../index.d.ts",