esoftplay 0.0.129 → 0.0.130
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/analyze.js +52 -0
- package/bin/build.js +0 -1
- package/bin/cli.js +21 -99
- package/bin/mover.js +108 -0
- package/bin/router.js +1 -0
- package/global.ts +39 -22
- package/lazy.ts +5 -1
- package/modules/lib/curl.ts +1 -4
- package/modules/lib/image.tsx +13 -9
- package/modules/lib/locale.ts +2 -2
- package/modules/lib/net_status.tsx +5 -2
- package/modules/lib/utils.ts +1 -1
- package/modules/use/tasks.ts +35 -0
- package/modules/user/class.ts +1 -1
- package/modules/user/index.tsx +1 -1
- package/modules/user/notification.tsx +1 -1
- package/package.json +1 -1
- package/render.tsx +17 -0
- package/state.ts +11 -6
- package/subscribe.ts +9 -4
package/bin/analyze.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
|
|
3
|
+
const importer = `\nimport useRenderCounter from 'esoftplay/render';`
|
|
4
|
+
const hook = (module) => `\n\tconst RC = useRenderCounter('${module}')`
|
|
5
|
+
const tag = `\t\t\t<RC />\n`
|
|
6
|
+
const param = process.argv[2]
|
|
7
|
+
|
|
8
|
+
if (param == 'clear') {
|
|
9
|
+
fs.readdirSync('./modules/').forEach((module) => {
|
|
10
|
+
if (fs.statSync('./modules/' + module).isDirectory()) {
|
|
11
|
+
fs.readdirSync('./modules/' + module).forEach((task) => {
|
|
12
|
+
let text = fs.readFileSync('./modules/' + module + '/' + task, { encoding: 'utf8' })
|
|
13
|
+
text = text.replace(importer, "")
|
|
14
|
+
text = text.replace(hook(module + '/' + task), "")
|
|
15
|
+
text = text.replace(tag, "")
|
|
16
|
+
fs.writeFileSync('./modules/' + module + '/' + task, text, { encoding: 'utf8' })
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
} else {
|
|
21
|
+
|
|
22
|
+
fs.readdirSync('./modules/').forEach((module) => {
|
|
23
|
+
if (fs.statSync('./modules/' + module).isDirectory()) {
|
|
24
|
+
fs.readdirSync('./modules/' + module).forEach((task) => {
|
|
25
|
+
let text = fs.readFileSync('./modules/' + module + '/' + task, { encoding: 'utf8' })
|
|
26
|
+
const importText = (/\n(import .*)\n/g).exec(text)
|
|
27
|
+
if (importText && importText.length > 1) {
|
|
28
|
+
const firstImport = importText[1]
|
|
29
|
+
text = text.replace(importer, "")
|
|
30
|
+
text = text.replace(firstImport, firstImport + importer)
|
|
31
|
+
const hooks = (/\n(export default function.*)\n/g).exec(text)
|
|
32
|
+
if (hooks && hooks.length > 1) {
|
|
33
|
+
const mainFunction = hooks[1]
|
|
34
|
+
text = text.replace(hook(module + '/' + task), "")
|
|
35
|
+
text = text.replace(mainFunction, mainFunction + hook(module + '/' + task))
|
|
36
|
+
let subText = (/(export default function.*\n})/gs).exec(text)
|
|
37
|
+
const render = (/(\n\s{2}return.*\n.*\>\n)/g).exec(subText)
|
|
38
|
+
if (subText && subText.length > 1 && render && render.length > 1) {
|
|
39
|
+
const mainRender = render[1]
|
|
40
|
+
let newSubText = subText[1].replace(tag, "")
|
|
41
|
+
newSubText = newSubText.replace(mainRender, mainRender + tag)
|
|
42
|
+
text = text.replace(subText[1], newSubText)
|
|
43
|
+
fs.writeFileSync('./modules/' + module + '/' + task, text, { encoding: 'utf8' })
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
console.log('SKIP => ' + module + '/' + task)
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
}
|
package/bin/build.js
CHANGED
package/bin/cli.js
CHANGED
|
@@ -32,6 +32,14 @@ if (args.length == 0) {
|
|
|
32
32
|
return
|
|
33
33
|
}
|
|
34
34
|
switch (args[0]) {
|
|
35
|
+
case "a":
|
|
36
|
+
case "analyze":
|
|
37
|
+
command('node ./node_modules/esoftplay/bin/analyze.js')
|
|
38
|
+
break
|
|
39
|
+
case "ac":
|
|
40
|
+
case "analyze clear":
|
|
41
|
+
command('node ./node_modules/esoftplay/bin/analyze.js clear')
|
|
42
|
+
break;
|
|
35
43
|
case "help":
|
|
36
44
|
help()
|
|
37
45
|
break;
|
|
@@ -265,6 +273,7 @@ function update() {
|
|
|
265
273
|
}
|
|
266
274
|
})
|
|
267
275
|
}
|
|
276
|
+
command("node ./node_modules/esoftplay/bin/locale.js")
|
|
268
277
|
consoleSucces("esoftplay framework sudah diupdate!")
|
|
269
278
|
}
|
|
270
279
|
|
|
@@ -274,95 +283,7 @@ function createMaster(module_name) {
|
|
|
274
283
|
const index = `const moduleName = "` + module_name + `"
|
|
275
284
|
module.exports = { moduleName }`
|
|
276
285
|
const libs = "[]"
|
|
277
|
-
const mover =
|
|
278
|
-
const shell = require('child_process').execSync;
|
|
279
|
-
const merge = require('lodash/merge')
|
|
280
|
-
const { moduleName } = require("./index")
|
|
281
|
-
const assetsFonts = "assets/fonts"
|
|
282
|
-
/* copy directory */
|
|
283
|
-
if (fs.existsSync('../esoftplay/esp.ts')) {
|
|
284
|
-
if (fs.existsSync('../esoftplay/modules/' + moduleName))
|
|
285
|
-
shell('rm -r ../esoftplay/modules/' + moduleName)
|
|
286
|
-
shell("cp -r ./" + moduleName + " ../esoftplay/modules/")
|
|
287
|
-
} else {
|
|
288
|
-
throw "Mohon install esoftplay package terlebih dahulu"
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
function readAsJson(path) {
|
|
292
|
-
let out = ""
|
|
293
|
-
try {
|
|
294
|
-
out = JSON.parse(fs.readFileSync(path, { encoding: 'utf8' }))
|
|
295
|
-
} catch(e) {
|
|
296
|
-
|
|
297
|
-
}
|
|
298
|
-
return out;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
function injectConfig(configPath) {
|
|
302
|
-
if (fs.existsSync(configPath)) {
|
|
303
|
-
const exsConf = readAsJson(configPath)
|
|
304
|
-
const conf = readAsJson("./config.json")
|
|
305
|
-
let _cf = merge({ config: conf }, exsConf)
|
|
306
|
-
fs.writeFileSync(configPath, JSON.stringify({..._cf}, undefined, 2))
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/* injectConfig */
|
|
311
|
-
injectConfig("../../config.json")
|
|
312
|
-
injectConfig("../../config.live.json")
|
|
313
|
-
injectConfig("../../config.debug.json")
|
|
314
|
-
|
|
315
|
-
/* move assets */
|
|
316
|
-
if (fs.existsSync("./assets/")) {
|
|
317
|
-
if (!fs.existsSync("../../assets/" + moduleName))
|
|
318
|
-
shell("mkdir -p ../../assets/" + moduleName)
|
|
319
|
-
try {
|
|
320
|
-
shell("cp -r -n ./assets/* ../../assets/" + moduleName + "/")
|
|
321
|
-
} catch (error) { }
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
if (fs.existsSync("./fonts/")) {
|
|
325
|
-
if (!fs.existsSync("../../" + assetsFonts))
|
|
326
|
-
shell("mkdir -p ../../" + assetsFonts)
|
|
327
|
-
try {
|
|
328
|
-
shell("cp -r -n ./fonts/* ../../" + assetsFonts + "/")
|
|
329
|
-
} catch (error) { }
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
/* inject lang */
|
|
333
|
-
if (fs.existsSync("./id.json")) {
|
|
334
|
-
let moduleLang = readAsJson("./id.json")
|
|
335
|
-
if (fs.existsSync("../../assets/locale/id.json")) {
|
|
336
|
-
let projectLang = readAsJson("../../assets/locale/id.json")
|
|
337
|
-
let _lg = merge(moduleLang, projectLang)
|
|
338
|
-
moduleLang = {..._lg}
|
|
339
|
-
}
|
|
340
|
-
fs.writeFileSync("../../assets/locale/id.json", JSON.stringify(moduleLang, undefined, 2))
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
/* inject libs */
|
|
344
|
-
if (fs.existsSync("./libs.json")) {
|
|
345
|
-
let libs = readAsJson("./libs.json")
|
|
346
|
-
let libsToSkip = []
|
|
347
|
-
libs.forEach((element, index) => {
|
|
348
|
-
console.log(element.split("@")[0])
|
|
349
|
-
if (fs.existsSync("../../node_modules/" + element.split("@")[0])) {
|
|
350
|
-
libsToSkip.push(element)
|
|
351
|
-
}
|
|
352
|
-
})
|
|
353
|
-
if (libsToSkip.length > 0) {
|
|
354
|
-
libsToSkip.forEach((lib) => {
|
|
355
|
-
libs = libs.filter((x) => x != lib)
|
|
356
|
-
console.log(lib + " is exist, Skipped")
|
|
357
|
-
})
|
|
358
|
-
}
|
|
359
|
-
if (libs.length > 0) {
|
|
360
|
-
console.log("mohon tunggu ..")
|
|
361
|
-
console.log("installing \\n" + libs.join("\\n"))
|
|
362
|
-
shell("cd ../../ && expo install " + libs.join(" && expo install "))
|
|
363
|
-
}
|
|
364
|
-
console.log("Success..!")
|
|
365
|
-
}`
|
|
286
|
+
const mover = ``
|
|
366
287
|
const packjson = `{
|
|
367
288
|
"name": "esoftplay-`+ module_name + `",
|
|
368
289
|
"version": "0.0.1",
|
|
@@ -370,7 +291,7 @@ function createMaster(module_name) {
|
|
|
370
291
|
"main": "index.js",
|
|
371
292
|
"scripts": {
|
|
372
293
|
"test": "echo \\"Error: no test specified\\" && exit 1",
|
|
373
|
-
"postinstall": "node
|
|
294
|
+
"postinstall": "node ../esoftplay/bin/mover.js esoftplay-`+ module_name + `"
|
|
374
295
|
},
|
|
375
296
|
"keywords": [
|
|
376
297
|
"espftplay-`+ module_name + `",
|
|
@@ -787,6 +708,7 @@ function configAvailable(enabled) {
|
|
|
787
708
|
}
|
|
788
709
|
|
|
789
710
|
function build() {
|
|
711
|
+
const local = args[1] == 'local' ? ' --local' : ''
|
|
790
712
|
const types = isWeb
|
|
791
713
|
?
|
|
792
714
|
[
|
|
@@ -802,7 +724,7 @@ function build() {
|
|
|
802
724
|
[
|
|
803
725
|
{
|
|
804
726
|
name: "1. IOS (Development) - Simulator",
|
|
805
|
-
cmd: "eas build --platform ios --profile development",
|
|
727
|
+
cmd: "eas build --platform ios --profile development" + local,
|
|
806
728
|
pre: () => {
|
|
807
729
|
configAvailable(true)
|
|
808
730
|
devClientPre(appjson)
|
|
@@ -814,7 +736,7 @@ function build() {
|
|
|
814
736
|
},
|
|
815
737
|
{
|
|
816
738
|
name: "2. IOS (Preview) - Simulator",
|
|
817
|
-
cmd: "eas build --platform ios --profile preview",
|
|
739
|
+
cmd: "eas build --platform ios --profile preview" + local,
|
|
818
740
|
pre: () => {
|
|
819
741
|
configAvailable(true)
|
|
820
742
|
devClientPos(appjson)
|
|
@@ -826,7 +748,7 @@ function build() {
|
|
|
826
748
|
},
|
|
827
749
|
{
|
|
828
750
|
name: "3. IOS (Preview) - Non Simulator",
|
|
829
|
-
cmd: "eas build --platform ios --profile preview_build",
|
|
751
|
+
cmd: "eas build --platform ios --profile preview_build" + local,
|
|
830
752
|
pre: () => {
|
|
831
753
|
configAvailable(true)
|
|
832
754
|
devClientPos(appjson)
|
|
@@ -838,7 +760,7 @@ function build() {
|
|
|
838
760
|
},
|
|
839
761
|
{
|
|
840
762
|
name: "4. IOS (Production) - ipa",
|
|
841
|
-
cmd: "eas build --platform ios --profile production",
|
|
763
|
+
cmd: "eas build --platform ios --profile production" + local,
|
|
842
764
|
pre: () => {
|
|
843
765
|
configAvailable(true)
|
|
844
766
|
devClientPos(appjson)
|
|
@@ -850,7 +772,7 @@ function build() {
|
|
|
850
772
|
},
|
|
851
773
|
{
|
|
852
774
|
name: "5. Android (Development) - apk",
|
|
853
|
-
cmd: "eas build --platform android --profile development",
|
|
775
|
+
cmd: "eas build --platform android --profile development" + local,
|
|
854
776
|
pre: () => {
|
|
855
777
|
configAvailable(true)
|
|
856
778
|
devClientPre(appjson)
|
|
@@ -862,7 +784,7 @@ function build() {
|
|
|
862
784
|
},
|
|
863
785
|
{
|
|
864
786
|
name: "6. Android (Preview) - apk",
|
|
865
|
-
cmd: "eas build --platform android --profile preview",
|
|
787
|
+
cmd: "eas build --platform android --profile preview" + local,
|
|
866
788
|
pre: () => {
|
|
867
789
|
configAvailable(true)
|
|
868
790
|
devClientPos(appjson)
|
|
@@ -874,7 +796,7 @@ function build() {
|
|
|
874
796
|
},
|
|
875
797
|
{
|
|
876
798
|
name: "7. Android (Production) - aab",
|
|
877
|
-
cmd: "eas build --platform android --profile production",
|
|
799
|
+
cmd: "eas build --platform android --profile production" + local,
|
|
878
800
|
pre: () => {
|
|
879
801
|
configAvailable(true)
|
|
880
802
|
devClientPos(appjson)
|
|
@@ -892,8 +814,8 @@ function build() {
|
|
|
892
814
|
input: process.stdin,
|
|
893
815
|
output: process.stdout
|
|
894
816
|
});
|
|
895
|
-
|
|
896
|
-
rl.question("Pilih build type :\n\n" + types.map((x) => x.name).join("\n") + '\n\nMasukkan nomor build type: ', function (idx) {
|
|
817
|
+
const local = args[1] == 'local' ? ' --local' : ''
|
|
818
|
+
rl.question((local ? "Pilih build type dengan mode LOCAL :\n\n" : "Pilih build type :\n\n") + types.map((x) => x.name).join("\n") + '\n\nMasukkan nomor build type: ', function (idx) {
|
|
897
819
|
d = types[idx - 1]
|
|
898
820
|
rl.close();
|
|
899
821
|
});
|
package/bin/mover.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const shell = require('child_process').execSync;
|
|
3
|
+
const merge = require('lodash/merge')
|
|
4
|
+
const assetsFonts = "assets/fonts"
|
|
5
|
+
let args = process.argv.slice(2);
|
|
6
|
+
|
|
7
|
+
if (args.length == 0) {
|
|
8
|
+
console.log("Argumen tidak boleh kosong");
|
|
9
|
+
return
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const mainModule = args[0]
|
|
13
|
+
const moduleName = args[0]?.split("-")?.[1]
|
|
14
|
+
|
|
15
|
+
/* copy directory */
|
|
16
|
+
if (fs.existsSync('../esoftplay/esp.ts')) {
|
|
17
|
+
if (fs.existsSync('../esoftplay/modules/' + moduleName))
|
|
18
|
+
shell('rm -r ../esoftplay/modules/' + moduleName)
|
|
19
|
+
shell("cp -r ../" + mainModule + "/" + moduleName + " ../esoftplay/modules/")
|
|
20
|
+
} else {
|
|
21
|
+
throw "Mohon install esoftplay package terlebih dahulu"
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function readAsJson(path) {
|
|
25
|
+
let out = ""
|
|
26
|
+
try {
|
|
27
|
+
out = JSON.parse(fs.readFileSync(path, { encoding: 'utf8' }))
|
|
28
|
+
} catch (e) {
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function injectConfig(configPath) {
|
|
35
|
+
if (fs.existsSync(configPath)) {
|
|
36
|
+
const config = "../" + mainModule + "/config.json"
|
|
37
|
+
const exsConf = readAsJson(configPath)
|
|
38
|
+
const conf = readAsJson(config)
|
|
39
|
+
let _cf = merge({ config: conf }, exsConf)
|
|
40
|
+
fs.writeFileSync(configPath, JSON.stringify({ ..._cf }, undefined, 2))
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* injectConfig */
|
|
45
|
+
injectConfig("../../config.json")
|
|
46
|
+
injectConfig("../../config.live.json")
|
|
47
|
+
injectConfig("../../config.debug.json")
|
|
48
|
+
|
|
49
|
+
/* move assets */
|
|
50
|
+
if (fs.existsSync("../" + mainModule + "/assets/")) {
|
|
51
|
+
console.log("ADA ASSETS");
|
|
52
|
+
if (!fs.existsSync("../../assets/" + moduleName))
|
|
53
|
+
shell("mkdir -p ../../assets/" + moduleName)
|
|
54
|
+
try {
|
|
55
|
+
shell("cp -r -n ../" + mainModule + "/assets/* ../../assets/" + moduleName + "/")
|
|
56
|
+
} catch (error) { }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (fs.existsSync("../" + mainModule + "/fonts/")) {
|
|
60
|
+
console.log("ADA FONTS");
|
|
61
|
+
if (!fs.existsSync("../../" + assetsFonts))
|
|
62
|
+
shell("mkdir -p ../../" + assetsFonts)
|
|
63
|
+
try {
|
|
64
|
+
shell("cp -r -n ../" + mainModule + "/fonts/* ../../" + assetsFonts + "/")
|
|
65
|
+
} catch (error) { }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/* inject lang */
|
|
69
|
+
if (fs.existsSync("../" + mainModule + "/id.json")) {
|
|
70
|
+
let moduleLang = readAsJson("../" + mainModule + "/id.json")
|
|
71
|
+
if (fs.existsSync("../../assets/locale/id.json")) {
|
|
72
|
+
let projectLang = readAsJson("../../assets/locale/id.json")
|
|
73
|
+
let _lg = merge(moduleLang, projectLang)
|
|
74
|
+
moduleLang = { ..._lg }
|
|
75
|
+
}
|
|
76
|
+
fs.writeFileSync("../../assets/locale/id.json", JSON.stringify(moduleLang, undefined, 2))
|
|
77
|
+
/* sort id.JSON */
|
|
78
|
+
shell("cd ../../ && node ./node_modules/esoftplay/bin/locale.js")
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/* inject libs */
|
|
82
|
+
if (fs.existsSync("../" + mainModule + "/libs.json")) {
|
|
83
|
+
let libs = readAsJson("../" + mainModule + "/libs.json")
|
|
84
|
+
let libsToSkip = []
|
|
85
|
+
libs.forEach((element, index) => {
|
|
86
|
+
console.log(element.split("@")[0])
|
|
87
|
+
if (fs.existsSync("../../node_modules/" + element.split("@")[0])) {
|
|
88
|
+
libsToSkip.push(element)
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
if (libsToSkip.length > 0) {
|
|
92
|
+
libsToSkip.forEach((lib) => {
|
|
93
|
+
libs = libs.filter((x) => x != lib)
|
|
94
|
+
console.log(lib + " is exist, Skipped")
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
if (libs.length > 0) {
|
|
98
|
+
console.log("mohon tunggu ..")
|
|
99
|
+
console.log("installing \\n" + libs.join("\\n"))
|
|
100
|
+
shell("cd ../../ && expo install " + libs.join(" && expo install "))
|
|
101
|
+
}
|
|
102
|
+
console.log("Success..!")
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/* execute mover on master */
|
|
106
|
+
if (fs.existsSync("../" + mainModule + "/mover.js")) {
|
|
107
|
+
shell("node ../" + mainModule + "/mover.js", { stdio: 'inherit' })
|
|
108
|
+
}
|
package/bin/router.js
CHANGED
package/global.ts
CHANGED
|
@@ -21,6 +21,7 @@ export interface useGlobalOption {
|
|
|
21
21
|
listener?: (data: any) => void,
|
|
22
22
|
jsonBeautify?: boolean,
|
|
23
23
|
isUserData?: boolean,
|
|
24
|
+
loadOnInit?: boolean,
|
|
24
25
|
onFinish?: () => void
|
|
25
26
|
}
|
|
26
27
|
|
|
@@ -46,31 +47,42 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
|
|
|
46
47
|
if (!_global.useGlobalSubscriber[_idx])
|
|
47
48
|
_global.useGlobalSubscriber[_idx] = [];
|
|
48
49
|
let value: T = initValue;
|
|
50
|
+
let loaded = -1
|
|
49
51
|
|
|
50
52
|
if (o?.persistKey) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
53
|
+
loaded = 0
|
|
54
|
+
if (o?.loadOnInit)
|
|
55
|
+
loadFromDisk()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
function loadFromDisk() {
|
|
60
|
+
if (loaded == 0) {
|
|
61
|
+
loaded = 1
|
|
62
|
+
let persistKey = o?.persistKey
|
|
63
|
+
STORAGE.getItem(persistKey).then((p: any) => {
|
|
64
|
+
if (p) {
|
|
65
|
+
if (persistKey != '__globalReady')
|
|
66
|
+
if (p != undefined && typeof p == 'string' && (p.startsWith("{") || p.startsWith("[")))
|
|
67
|
+
try { set(JSON.parse(p)) } catch (error) { }
|
|
68
|
+
else {
|
|
69
|
+
if (p == "true" || p == "false") {
|
|
70
|
+
try { /* @ts-ignore */ set(eval(p)) } catch (error) { }
|
|
71
|
+
} else if (isNaN(p)) {
|
|
72
|
+
try { /* @ts-ignore */ set(p) } catch (error) { }
|
|
73
|
+
} else {
|
|
74
|
+
try { /* @ts-ignore */ set(eval(p)) } catch (error) { }
|
|
75
|
+
}
|
|
64
76
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
77
|
+
}
|
|
78
|
+
if (o?.onFinish) {
|
|
79
|
+
clearTimeout(timeoutFinish)
|
|
80
|
+
timeoutFinish = setTimeout(() => {
|
|
81
|
+
o.onFinish?.()
|
|
82
|
+
}, 50);
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
}
|
|
74
86
|
}
|
|
75
87
|
|
|
76
88
|
|
|
@@ -116,6 +128,8 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
|
|
|
116
128
|
}
|
|
117
129
|
|
|
118
130
|
function useSelector(se: (state: T) => any): void {
|
|
131
|
+
loadFromDisk()
|
|
132
|
+
|
|
119
133
|
let [l, s] = R.useState<any>(se(value));
|
|
120
134
|
|
|
121
135
|
let sl = R.useCallback(
|
|
@@ -141,6 +155,7 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
|
|
|
141
155
|
}
|
|
142
156
|
|
|
143
157
|
function get(param?: string, ...params: string[]): any {
|
|
158
|
+
loadFromDisk()
|
|
144
159
|
let out: any = value;
|
|
145
160
|
if (param) {
|
|
146
161
|
const _params = [param, ...params]
|
|
@@ -155,6 +170,8 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
|
|
|
155
170
|
|
|
156
171
|
|
|
157
172
|
function useState(): [T, (newState: T) => void, () => T] {
|
|
173
|
+
loadFromDisk()
|
|
174
|
+
|
|
158
175
|
let [l, s] = R.useState<T>(value);
|
|
159
176
|
|
|
160
177
|
let sl = R.useCallback((ns: T) => { s(ns) }, []);
|
package/lazy.ts
CHANGED
|
@@ -12,7 +12,11 @@ export default function useLazyState<T>(initialState?: T): [T, (newValue: T) =>
|
|
|
12
12
|
|
|
13
13
|
const setter = (newValue: T) => {
|
|
14
14
|
if (isMounted.current) {
|
|
15
|
-
|
|
15
|
+
if (typeof newValue == 'function') {
|
|
16
|
+
value.current = newValue(value.current)
|
|
17
|
+
} else {
|
|
18
|
+
value.current = newValue;
|
|
19
|
+
}
|
|
16
20
|
}
|
|
17
21
|
return () => {
|
|
18
22
|
if (isMounted.current) {
|
package/modules/lib/curl.ts
CHANGED
|
@@ -57,11 +57,8 @@ export default class m {
|
|
|
57
57
|
this.withHeader = this.withHeader.bind(this);
|
|
58
58
|
this.initTimeout = this.initTimeout.bind(this);
|
|
59
59
|
this.cancelTimeout = this.cancelTimeout.bind(this);
|
|
60
|
-
|
|
61
|
-
if (uri && str.isOnline) {
|
|
60
|
+
if (uri) {
|
|
62
61
|
this.init(uri, post, onDone, onFailed, debug);
|
|
63
|
-
} else if (!str.isOnline && onFailed) {
|
|
64
|
-
onFailed({ message: this.refineErrorMessage("Failed to access") }, false);
|
|
65
62
|
}
|
|
66
63
|
}
|
|
67
64
|
|
package/modules/lib/image.tsx
CHANGED
|
@@ -242,20 +242,24 @@ class m extends LibComponent<LibImageProps, LibImageState> {
|
|
|
242
242
|
var wantedMaxSize = maxDimension || 1280
|
|
243
243
|
var rawheight = result.height
|
|
244
244
|
var rawwidth = result.width
|
|
245
|
-
|
|
246
|
-
if (rawheight
|
|
247
|
-
|
|
248
|
-
var
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
245
|
+
let doResize = false
|
|
246
|
+
if (wantedMaxSize < Math.max(rawheight, rawwidth)) {
|
|
247
|
+
doResize = true
|
|
248
|
+
var ratio = rawwidth / rawheight
|
|
249
|
+
if (rawheight > rawwidth) {
|
|
250
|
+
var wantedwidth = wantedMaxSize * ratio;
|
|
251
|
+
var wantedheight = wantedMaxSize;
|
|
252
|
+
} else {
|
|
253
|
+
var wantedwidth = wantedMaxSize;
|
|
254
|
+
var wantedheight = wantedMaxSize / ratio;
|
|
255
|
+
}
|
|
252
256
|
}
|
|
253
257
|
|
|
254
258
|
setTimeout(async () => {
|
|
255
259
|
const manipImage = await ImageManipulator.manipulateAsync(
|
|
256
260
|
result.uri,
|
|
257
|
-
[{ resize: { width: wantedwidth, height: wantedheight } }],
|
|
258
|
-
{ format: SaveFormat.JPEG }
|
|
261
|
+
doResize ? [{ resize: { width: wantedwidth, height: wantedheight } }] : [],
|
|
262
|
+
{ format: SaveFormat.JPEG, compress: 1.0 }
|
|
259
263
|
);
|
|
260
264
|
new LibCurl().upload('image_upload', "image", String(manipImage.uri), 'image/jpeg',
|
|
261
265
|
(res: any, msg: string) => {
|
package/modules/lib/locale.ts
CHANGED
|
@@ -6,8 +6,8 @@ import useGlobalState from 'esoftplay/global';
|
|
|
6
6
|
import { NativeModules, Platform } from 'react-native';
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
const state = useGlobalState("id", { persistKey: 'lib_locale_lang' })
|
|
10
|
-
const lang = useGlobalState({}, { persistKey: 'lib_locale_lang_data', inFile: true })
|
|
9
|
+
const state = useGlobalState("id", { persistKey: 'lib_locale_lang', loadOnInit: true })
|
|
10
|
+
const lang = useGlobalState({}, { persistKey: 'lib_locale_lang_data', inFile: true, loadOnInit: true })
|
|
11
11
|
|
|
12
12
|
export default class m {
|
|
13
13
|
|
|
@@ -39,7 +39,7 @@ class net_status extends LibComponent<LibNet_statusProps, LibNet_statusState> {
|
|
|
39
39
|
componentDidMount(): void {
|
|
40
40
|
super.componentDidMount()
|
|
41
41
|
this.unsubscribe = NetInfo.addEventListener(state => {
|
|
42
|
-
this.onChangeConnectivityStatus(!!state.isConnected, state.isInternetReachable)
|
|
42
|
+
this.onChangeConnectivityStatus(!!state.isConnected, !!state.isInternetReachable)
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -52,12 +52,15 @@ class net_status extends LibComponent<LibNet_statusProps, LibNet_statusState> {
|
|
|
52
52
|
let isOnline = isConnected && isInternetReachable
|
|
53
53
|
net_status.setOnline(isConnected, isInternetReachable)
|
|
54
54
|
if (isOnline) {
|
|
55
|
+
clearTimeout(this.timeout)
|
|
55
56
|
this.timeout = setTimeout(() => {
|
|
56
57
|
this.setState({ zeroHeight: 1 })
|
|
57
58
|
}, 1500)
|
|
58
59
|
} else {
|
|
59
|
-
this.setState({ zeroHeight: 2 })
|
|
60
60
|
clearTimeout(this.timeout)
|
|
61
|
+
this.timeout = setTimeout(() => {
|
|
62
|
+
this.setState({ zeroHeight: 2 })
|
|
63
|
+
}, 600)
|
|
61
64
|
}
|
|
62
65
|
}
|
|
63
66
|
|
package/modules/lib/utils.ts
CHANGED
|
@@ -19,7 +19,7 @@ export interface LibUtilsDate {
|
|
|
19
19
|
|
|
20
20
|
export type LibUtilsTravelMode = 'driving' | 'walking'
|
|
21
21
|
let installationIdDefault
|
|
22
|
-
const installationId = useGlobalState(installationIdDefault, { persistKey: 'deviceId' })
|
|
22
|
+
const installationId = useGlobalState(installationIdDefault, { persistKey: 'deviceId', loadOnInit: true })
|
|
23
23
|
const cache = useGlobalState<any>({ inDebounce: undefined })
|
|
24
24
|
export default class eutils {
|
|
25
25
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// useLibs
|
|
2
|
+
|
|
3
|
+
import { useLazyState } from "esoftplay";
|
|
4
|
+
import { useRef } from "react";
|
|
5
|
+
|
|
6
|
+
export default function m<T>(task: (item: T) => Promise<void>, onDone?: () => void): [(data: T[], success?: (isSuccess: boolean) => void) => void, number] {
|
|
7
|
+
const [counter, setCounter, getCounter] = useLazyState(0)
|
|
8
|
+
const onProcess = useRef(false)
|
|
9
|
+
|
|
10
|
+
function run(data: any[], cb?: (isSuccess: boolean) => void) {
|
|
11
|
+
if (onProcess.current == true) {
|
|
12
|
+
if (cb) cb?.(false);
|
|
13
|
+
} else {
|
|
14
|
+
onProcess.current = true;
|
|
15
|
+
if (cb) cb?.(true);
|
|
16
|
+
setCounter(0)()
|
|
17
|
+
try {
|
|
18
|
+
(async () => {
|
|
19
|
+
for (let i = 0; i < data.length; i++) {
|
|
20
|
+
const item = data[i];
|
|
21
|
+
await task(item);
|
|
22
|
+
if (i == (data.length - 1)) {
|
|
23
|
+
if (onDone)
|
|
24
|
+
onDone()
|
|
25
|
+
onProcess.current = false;
|
|
26
|
+
}
|
|
27
|
+
setCounter(getCounter() + 1)()
|
|
28
|
+
}
|
|
29
|
+
})()
|
|
30
|
+
} catch (err) { }
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return [run, counter]
|
|
35
|
+
}
|
package/modules/user/class.ts
CHANGED
|
@@ -12,7 +12,7 @@ import Constants from 'expo-constants';
|
|
|
12
12
|
import * as Notifications from 'expo-notifications';
|
|
13
13
|
import { Platform } from 'react-native';
|
|
14
14
|
|
|
15
|
-
const state = useGlobalState(null, { persistKey: "user" })
|
|
15
|
+
const state = useGlobalState(null, { persistKey: "user", loadOnInit: true })
|
|
16
16
|
|
|
17
17
|
export default class m {
|
|
18
18
|
static state(): useGlobalReturn<any> {
|
package/modules/user/index.tsx
CHANGED
|
@@ -53,7 +53,7 @@ function setFonts(): Promise<void> {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
|
|
56
|
-
const route = useGlobalState<any>(undefined, { persistKey: 'user_index_routes_initial', inFile: true })
|
|
56
|
+
const route = useGlobalState<any>(undefined, { persistKey: 'user_index_routes_initial', inFile: true, loadOnInit: true })
|
|
57
57
|
export default function m(props: UserIndexProps): any {
|
|
58
58
|
const [langId] = LibLocale.state().useState()
|
|
59
59
|
moment().locale(langId)
|
|
@@ -28,7 +28,7 @@ const initState = {
|
|
|
28
28
|
unread: 0
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
const state = useGlobalState<any>(initState, { persistKey: "user_notification_data", isUserData: true })
|
|
31
|
+
const state = useGlobalState<any>(initState, { persistKey: "user_notification_data", isUserData: true, loadOnInit: true })
|
|
32
32
|
class m extends LibComponent<UserNotificationProps, UserNotificationState> {
|
|
33
33
|
|
|
34
34
|
static state(): useGlobalReturn<any> {
|
package/package.json
CHANGED
package/render.tsx
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// useLibs
|
|
2
|
+
// noPage
|
|
3
|
+
|
|
4
|
+
import { useEffect, useRef } from 'react';
|
|
5
|
+
import { Text } from 'react-native';
|
|
6
|
+
|
|
7
|
+
export default function useRenderCounter(module: string): any {
|
|
8
|
+
const counter = useRef(1)
|
|
9
|
+
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
counter.current += 1
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
return () => (
|
|
15
|
+
<Text style={{ position: 'absolute', fontSize: 7, zIndex: 999, color: 'white', backgroundColor: 'black', bottom: 0, left: 0 }} >{module}: {counter.current}</Text>
|
|
16
|
+
)
|
|
17
|
+
}
|
package/state.ts
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
2
|
|
|
3
|
-
type useSafeStateReturn<T> = [T | undefined, (value: T | undefined) => void, () => T];
|
|
3
|
+
type useSafeStateReturn<T> = [T | undefined, (value: T | undefined) => void, () => T | undefined];
|
|
4
4
|
|
|
5
5
|
export default function useSafeState<T = any>(defaultValue?: T): useSafeStateReturn<T> {
|
|
6
6
|
const isMountedRef = useRef<boolean>(true);
|
|
7
|
-
const
|
|
7
|
+
const valueRef = useRef(defaultValue)
|
|
8
|
+
const [, rerender] = useState({})
|
|
8
9
|
|
|
9
10
|
const updateState = useCallback((value: T | undefined) => {
|
|
10
11
|
if (isMountedRef.current) {
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
if (typeof value == 'function') {
|
|
13
|
+
valueRef.current = value(valueRef.current)
|
|
14
|
+
} else {
|
|
15
|
+
valueRef.current = value;
|
|
16
|
+
}
|
|
17
|
+
rerender({})
|
|
13
18
|
}
|
|
14
19
|
}, []);
|
|
15
20
|
|
|
16
21
|
const getter = () => {
|
|
17
|
-
return
|
|
22
|
+
return valueRef.current
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
useEffect(() => {
|
|
@@ -24,5 +29,5 @@ export default function useSafeState<T = any>(defaultValue?: T): useSafeStateRet
|
|
|
24
29
|
};
|
|
25
30
|
}, []);
|
|
26
31
|
|
|
27
|
-
return [
|
|
32
|
+
return [valueRef.current, updateState, getter];
|
|
28
33
|
}
|
package/subscribe.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// useLibs
|
|
2
2
|
|
|
3
3
|
import React from 'react';
|
|
4
|
+
import { InteractionManager } from 'react-native';
|
|
4
5
|
|
|
5
6
|
export interface useGlobalSubscriberReturn {
|
|
6
7
|
getValue: () => any,
|
|
@@ -24,7 +25,7 @@ export default function useGlobalSubscriber(defaultValue?: any): useGlobalSubscr
|
|
|
24
25
|
const trigger = (newValue?: any) => {
|
|
25
26
|
notify(newValue);
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
+
|
|
28
29
|
function useSubscribe(func: Function) {
|
|
29
30
|
React.useLayoutEffect(() => {
|
|
30
31
|
subscribers.add(func)
|
|
@@ -33,13 +34,17 @@ export default function useGlobalSubscriber(defaultValue?: any): useGlobalSubscr
|
|
|
33
34
|
if (subscribers.size == 0) reset()
|
|
34
35
|
}
|
|
35
36
|
}, [])
|
|
36
|
-
|
|
37
|
+
|
|
37
38
|
return trigger;
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
+
|
|
40
41
|
function notify(newValue?: any) {
|
|
41
42
|
value = newValue;
|
|
42
|
-
subscribers.forEach((fun: Function) =>
|
|
43
|
+
subscribers.forEach((fun: Function) => {
|
|
44
|
+
InteractionManager.runAfterInteractions(() => {
|
|
45
|
+
fun?.(newValue)
|
|
46
|
+
})
|
|
47
|
+
});
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
return {
|