esoftplay 0.0.117-t → 0.0.117-u

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 (2) hide show
  1. package/global.ts +27 -29
  2. package/package.json +1 -1
package/global.ts CHANGED
@@ -37,7 +37,6 @@ class Context {
37
37
  }
38
38
 
39
39
  export const globalIdx = new Context()
40
- let duplicateDelay = 500
41
40
  export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): useGlobalReturn<T> {
42
41
  const STORAGE = o?.inFile ? new Storage() : AsyncStorage
43
42
  const _idx = globalIdx.idx
@@ -47,35 +46,34 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
47
46
 
48
47
  if (o?.persistKey) {
49
48
  let persistKey = o?.persistKey
50
- setTimeout(() => {
51
- STORAGE.getItem(persistKey).then((p) => {
52
- if (p) {
53
- // if (persistKey == 'lib_apitest_debug') {
54
- // console.log(p)
55
- // }
56
- // const byteSize = str => new Blob([str]).size;
57
- // function bytesToSize(bytes) {
58
- // var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
59
- // if (bytes == 0) return '0 Byte';
60
- // var i = parseInt(String(Math.floor(Math.log(bytes) / Math.log(1024))));
61
- // return Math.round(bytes / Math.pow(1024, i)) + ' ' + sizes[i];
62
- // }
63
- // console.log(persistKey + ' => ' + bytesToSize(byteSize(p)))
64
- if (p.includes("\\\\\\\\")) {
65
- if (persistKey)
66
- STORAGE.clear()
67
- return
68
- }
69
- if (p.startsWith("{") || p.startsWith("["))
70
- try { set(JSON.parse(p)) } catch (error) { }
71
- else
72
- try {
73
- // @ts-ignore
74
- set(p)
75
- } catch (error) { }
49
+ STORAGE.getItem(persistKey).then((p) => {
50
+ if (p) {
51
+ console.log(persistKey + " = " + p?.length)
52
+ // if (persistKey == 'lib_apitest_debug') {
53
+ // console.log(p)
54
+ // }
55
+ // const byteSize = str => new Blob([str]).size;
56
+ // function bytesToSize(bytes) {
57
+ // var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
58
+ // if (bytes == 0) return '0 Byte';
59
+ // var i = parseInt(String(Math.floor(Math.log(bytes) / Math.log(1024))));
60
+ // return Math.round(bytes / Math.pow(1024, i)) + ' ' + sizes[i];
61
+ // }
62
+ // console.log(persistKey + ' => ' + bytesToSize(byteSize(p)))
63
+ if (p.includes("\\\\\\\\")) {
64
+ if (persistKey)
65
+ STORAGE.clear()
66
+ return
76
67
  }
77
- })
78
- }, duplicateDelay * _idx);
68
+ if (p.startsWith("{") || p.startsWith("["))
69
+ try { set(JSON.parse(p)) } catch (error) { }
70
+ else
71
+ try {
72
+ // @ts-ignore
73
+ set(p)
74
+ } catch (error) { }
75
+ }
76
+ })
79
77
  }
80
78
 
81
79
  /* register to userData to automatically reset state and persist */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esoftplay",
3
- "version": "0.0.117-t",
3
+ "version": "0.0.117-u",
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",