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.
- package/global.ts +27 -29
- 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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
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 */
|