esoftplay 0.0.136-i → 0.0.136-k

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.
Files changed (3) hide show
  1. package/global.ts +34 -48
  2. package/mmkv.ts +2 -2
  3. package/package.json +1 -1
package/global.ts CHANGED
@@ -17,31 +17,19 @@ 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
- }
31
20
 
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;
21
+ export interface useGlobalOption {
22
+ persistKey?: string,
23
+ inFile?: boolean,
24
+ inFastStorage?: boolean,
25
+ listener?: (data: any) => void,
26
+ useAutoSync?: useGlobalAutoSync,
27
+ jsonBeautify?: boolean,
28
+ isUserData?: boolean,
29
+ loadOnInit?: boolean,
30
+ onFinish?: () => void
42
31
  }
43
32
 
44
- export type useGlobalOption = useGlobalOptionA | useGlobalOptionB;
45
33
  export interface useGlobalConnect<T> {
46
34
  render: (props: T) => any,
47
35
  }
@@ -57,10 +45,7 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
57
45
  let sync: any = undefined
58
46
 
59
47
  if (o?.persistKey) {
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
+ STORAGE = o?.inFastStorage ? require('esoftplay/mmkv').default : (o?.inFile ? (require('esoftplay/storage').default) : (require('@react-native-async-storage/async-storage').default))
64
49
  loaded = 0
65
50
  if (o?.loadOnInit)
66
51
  loadFromDisk()
@@ -98,32 +83,33 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
98
83
  })[0]
99
84
  }
100
85
 
101
- async function loadFromDisk() {
86
+ function loadFromDisk() {
102
87
  if (loaded == 0) {
103
88
  loaded = 1
104
89
  let persistKey = o?.persistKey
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) { }
90
+ STORAGE.getItem(String(persistKey)).then((p: any) => {
91
+ if (p) {
92
+ if (persistKey != '__globalReady')
93
+ if (p != undefined && typeof p == 'string' && (p.startsWith("{") || p.startsWith("[")))
94
+ try { set(JSON.parse(p)) } catch (error) { }
95
+ else {
96
+ if (p == "true" || p == "false") {
97
+ try { /* @ts-ignore */ set(eval(p)) } catch (error) { }
98
+ } else if (isNaN(p)) {
99
+ try { /* @ts-ignore */ set(p) } catch (error) { }
100
+ } else {
101
+ try { /* @ts-ignore */ set(eval(p)) } catch (error) { }
102
+ }
117
103
  }
118
- }
119
- }
120
- if (o?.onFinish) {
121
- clearTimeout(timeoutFinish)
122
- timeoutFinish = setTimeout(() => {
123
- o.onFinish?.()
104
+ }
105
+ if (o?.onFinish) {
124
106
  clearTimeout(timeoutFinish)
125
- }, 50);
126
- }
107
+ timeoutFinish = setTimeout(() => {
108
+ o.onFinish?.()
109
+ clearTimeout(timeoutFinish)
110
+ }, 50);
111
+ }
112
+ })
127
113
  }
128
114
  }
129
115
 
@@ -181,7 +167,7 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
181
167
  set(initValue)
182
168
  }
183
169
 
184
- async function useSelector(se: (state: T) => any): void {
170
+ function useSelector(se: (state: T) => any): void {
185
171
  loadFromDisk()
186
172
 
187
173
  let [l, s] = R.useState<any>(se(value));
package/mmkv.ts CHANGED
@@ -3,8 +3,8 @@ import { MMKV } from 'react-native-mmkv';
3
3
  const storage = new MMKV()
4
4
 
5
5
  const FastStorage = {
6
- getItem(key: string): string | undefined {
7
- return storage.getString(key)
6
+ getItem(key: string): Promise<string | undefined | null> {
7
+ return new Promise((r) => r(storage.getString(key)))
8
8
  },
9
9
  setItem(key: string, value: string) {
10
10
  storage.set(key, value)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esoftplay",
3
- "version": "0.0.136-i",
3
+ "version": "0.0.136-k",
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",