esoftplay 0.0.129-u → 0.0.129-w

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 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/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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esoftplay",
3
- "version": "0.0.129-u",
3
+ "version": "0.0.129-w",
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",
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
@@ -9,7 +9,11 @@ export default function useSafeState<T = any>(defaultValue?: T): useSafeStateRet
9
9
 
10
10
  const updateState = useCallback((value: T | undefined) => {
11
11
  if (isMountedRef.current) {
12
- valueRef.current = value;
12
+ if (typeof value == 'function') {
13
+ valueRef.current = value(valueRef.current)
14
+ } else {
15
+ valueRef.current = value;
16
+ }
13
17
  rerender({})
14
18
  }
15
19
  }, []);