esoftplay 0.0.269-beta4d33991 → 0.0.269-beta6ae30d2

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.
@@ -4,8 +4,8 @@
4
4
  import esp from 'esoftplay/esp';
5
5
  import { LibCrypt } from 'esoftplay/cache/lib/crypt/import';
6
6
  import { reportApiError } from "esoftplay/error";
7
+ import { File } from 'expo-file-system';
7
8
 
8
- //api_logger_import
9
9
 
10
10
  /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/curl.md) untuk melihat dokumentasi*/
11
11
  export default class m {
@@ -30,7 +30,7 @@ export default class m {
30
30
  }
31
31
 
32
32
  constructor(uri?: string, post?: any, onDone?: (res: any, msg: string) => void, onFailed?: (error: any, timeout: boolean) => void, debug?: number) {
33
- this.header = { version: esp.config()?.publish_id }
33
+ this.header = { version: (esp.config()?.publish_id).toString() }
34
34
  // this.maxRetry = 2;
35
35
  this.setUri = this.setUri.bind(this);
36
36
  this.setUrl = this.setUrl.bind(this);
@@ -356,11 +356,12 @@ export default class m {
356
356
  if (post) {
357
357
  if (upload) {
358
358
  let fd = new FormData();
359
- Object.keys(post).map(function (key) {
359
+ await Promise.all(Object.keys(post).map(async (key) => {
360
360
  if (post[key] !== undefined) {
361
- fd.append(key, post[key])
361
+ const file = new File(post[key].uri)
362
+ fd.append(key, file as any, post[key].name)
362
363
  }
363
- });
364
+ }));
364
365
  this.post = fd
365
366
  } else {
366
367
  let ps = Object.keys(post).map((key) => {
@@ -383,10 +384,9 @@ export default class m {
383
384
  this.setUrl(esp.config("url"))
384
385
  }
385
386
  await this.setHeader();
386
- if (upload)
387
- this.header["Content-Type"] = "multipart/form-data"
388
- else
387
+ if (!upload)
389
388
  this.header["Content-Type"] = "application/x-www-form-urlencoded;charset=UTF-8"
389
+
390
390
  let options: any = {
391
391
  method: !this.post ? "GET" : "POST",
392
392
  headers: this.header,
@@ -106,6 +106,8 @@ export default class m extends LibComponent<LibInfiniteProps, LibInfiniteState>
106
106
  }
107
107
  })
108
108
  page = 0
109
+ }
110
+ if (page == 0) {
109
111
  this.pages = []
110
112
  }
111
113
  var { url, post } = this.props
@@ -10,7 +10,7 @@ import { UserRoutes } from 'esoftplay/cache/user/routes/import';
10
10
 
11
11
  import esp from 'esoftplay/esp';
12
12
  import useGlobalState, { useGlobalReturn } from 'esoftplay/global';
13
- import React, { useEffect } from "react";
13
+ import React, { useEffect, useSyncExternalStore } from "react";
14
14
 
15
15
  export interface LibNavigationTabConfigReturn<S extends keyof EspArgsInterface> {
16
16
  activeIndex: number,
@@ -23,7 +23,44 @@ export interface LibNavigationInjector {
23
23
  children?: any
24
24
  }
25
25
 
26
- export const lastArgs = useGlobalState(undefined, { persistKey: "lib/navigation/lastargs" })
26
+ interface LibNavigationState {
27
+ redirect: Record<number, { func: Function }>,
28
+ data: Record<string | number, any>,
29
+ ref: any,
30
+ isReady: boolean
31
+ }
32
+
33
+ const initialNavigationState: LibNavigationState = {
34
+ redirect: {},
35
+ data: {},
36
+ ref: undefined,
37
+ isReady: false
38
+ }
39
+
40
+ let navigationState = initialNavigationState
41
+ const navigationSubscribers = new Set<() => void>()
42
+
43
+ const navigationStore = {
44
+ getSnapshot: () => navigationState,
45
+ subscribe: (callback: () => void) => {
46
+ navigationSubscribers.add(callback)
47
+ return () => navigationSubscribers.delete(callback)
48
+ },
49
+ setState: (nextState: LibNavigationState) => {
50
+ navigationState = nextState
51
+ navigationSubscribers.forEach((callback) => callback())
52
+ }
53
+ }
54
+
55
+ export function useNavigationState(): LibNavigationState {
56
+ return useSyncExternalStore(
57
+ navigationStore.subscribe,
58
+ navigationStore.getSnapshot,
59
+ navigationStore.getSnapshot
60
+ )
61
+ }
62
+
63
+ export const lastArgs = useGlobalState(undefined, { persistKey: "lib/navigation/lastargs", inFastStorage: true, loadOnInit: true })
27
64
 
28
65
  function logArgs(params: any) {
29
66
  lastArgs.set(params)
@@ -31,17 +68,25 @@ function logArgs(params: any) {
31
68
 
32
69
  /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md) untuk melihat dokumentasi*/
33
70
  export default {
34
- _redirect: {} as any,
35
- _data: {} as any,
36
- _ref: {} as any,
37
- _isReady: false,
71
+ get _redirect() {
72
+ return navigationStore.getSnapshot().redirect
73
+ },
74
+ get _data() {
75
+ return navigationStore.getSnapshot().data
76
+ },
77
+ get _ref() {
78
+ return navigationStore.getSnapshot().ref
79
+ },
80
+ get _isReady() {
81
+ return navigationStore.getSnapshot().isReady
82
+ },
38
83
  /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#setRef) untuk melihat dokumentasi*/
39
84
  setRef(ref: any): void {
40
- this._ref = ref
85
+ navigationStore.setState({ ...navigationStore.getSnapshot(), ref })
41
86
  },
42
87
  /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#setIsReady) untuk melihat dokumentasi*/
43
88
  setIsReady(isReady: boolean): void {
44
- this._isReady = isReady;
89
+ navigationStore.setState({ ...navigationStore.getSnapshot(), isReady });
45
90
  },
46
91
  /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#getIsReady) untuk melihat dokumentasi*/
47
92
  getIsReady(): boolean {
@@ -49,7 +94,8 @@ export default {
49
94
  },
50
95
  /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#setNavigation) untuk melihat dokumentasi*/
51
96
  setNavigation(nav: any): void {
52
- this._data._navigation = nav
97
+ const state = navigationStore.getSnapshot()
98
+ navigationStore.setState({ ...state, data: { ...state.data, _navigation: nav } })
53
99
  },
54
100
  /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#getArgs) untuk melihat dokumentasi*/
55
101
  getArgs(props: any, key: string, defOutput?: any): any {
@@ -72,45 +118,49 @@ export default {
72
118
  /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#setRedirect) untuk melihat dokumentasi*/
73
119
  setRedirect(func: Function, key?: number) {
74
120
  if (!key) key = 1
75
- this._redirect[key] = { func }
121
+ const state = navigationStore.getSnapshot()
122
+ navigationStore.setState({ ...state, redirect: { ...state.redirect, [key]: { func } } })
76
123
  },
77
124
  /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#delRedirect) untuk melihat dokumentasi*/
78
125
  delRedirect(key?: number) {
79
126
  if (!key) key = 1
80
- delete this._redirect[key]
127
+ const state = navigationStore.getSnapshot()
128
+ const redirect = { ...state.redirect }
129
+ delete redirect[key]
130
+ navigationStore.setState({ ...state, redirect })
81
131
  },
82
132
  /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#redirect) untuk melihat dokumentasi*/
83
133
  redirect(key?: number) {
84
134
  if (!key) key = 1
85
- if (this._redirect?.[key]) {
86
- const { func } = this._redirect?.[key]
135
+ const redirect = navigationStore.getSnapshot().redirect
136
+ if (redirect?.[key]) {
137
+ const { func } = redirect[key]
87
138
  if (typeof func == 'function')
88
139
  func()
89
- delete this._redirect[key]
140
+ const state = navigationStore.getSnapshot()
141
+ const nextRedirect = { ...state.redirect }
142
+ delete nextRedirect[key]
143
+ navigationStore.setState({ ...state, redirect: nextRedirect })
90
144
  }
91
145
  },
92
146
  /* <T EspRouterInterface>(path: T): EspRouterInterface[T] { */
93
147
  /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#navigate) untuk melihat dokumentasi*/
94
148
  navigate<S extends keyof EspArgsInterface>(route: S, params?: EspArgsInterface[S]): void {
95
149
  logArgs(params)
96
- doIt(() => {
97
- this._ref?.navigate?.(replaceModuleByUrlParam(params, route), params)
98
- })
150
+ this._ref?.navigate?.(replaceModuleByUrlParam(params, route), params)
99
151
  },
100
152
  /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#navigateTab) untuk melihat dokumentasi*/
101
153
  navigateTab<S extends keyof EspArgsInterface>(route: S, tabIndex: number, params?: EspArgsInterface[S]): void {
102
154
  logArgs(params)
103
- doIt(() => {
104
- this._ref?.navigate?.(replaceModuleByUrlParam(params, route), params)
105
- setTimeout(() => {
106
- const TabConfig = esp.modProp(replaceModuleByUrlParam(params, route))?.TabConfig;
107
- if (TabConfig) {
108
- TabConfig.set(esp.mod("lib/object").set(TabConfig.get(), tabIndex)('activeIndex'))
109
- } else {
110
- console.error("TabConfig not found or exported in module " + route);
111
- }
112
- }, 100);
113
- })
155
+ this._ref?.navigate?.(replaceModuleByUrlParam(params, route), params)
156
+ setTimeout(() => {
157
+ const TabConfig = esp.modProp(replaceModuleByUrlParam(params, route))?.TabConfig;
158
+ if (TabConfig) {
159
+ TabConfig.set(esp.mod("lib/object").set(TabConfig.get(), tabIndex)('activeIndex'))
160
+ } else {
161
+ console.error("TabConfig not found or exported in module " + route);
162
+ }
163
+ }, 100);
114
164
  },
115
165
  /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#createTabConfig) untuk melihat dokumentasi*/
116
166
  createTabConfig<S extends keyof EspArgsInterface>(modules: S[], defaultIndex?: number): useGlobalReturn<LibNavigationTabConfigReturn<S>> {
@@ -147,7 +197,10 @@ export default {
147
197
  key = 1
148
198
  }
149
199
  try {
150
- delete this._data[key]
200
+ const state = navigationStore.getSnapshot()
201
+ const data = { ...state.data }
202
+ delete data[key]
203
+ navigationStore.setState({ ...state, data })
151
204
  } catch (error) { }
152
205
  },
153
206
  /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#sendBackResult) untuk melihat dokumentasi*/
@@ -157,7 +210,10 @@ export default {
157
210
  }
158
211
  if (this._data[key] != undefined) {
159
212
  this._data[key](result)
160
- delete this._data[key]
213
+ const state = navigationStore.getSnapshot()
214
+ const data = { ...state.data }
215
+ delete data[key]
216
+ navigationStore.setState({ ...state, data })
161
217
  }
162
218
  this.back()
163
219
  },
@@ -172,13 +228,18 @@ export default {
172
228
  }
173
229
  params['_senderKey'] = key
174
230
  if (!this._data.hasOwnProperty(key) && key != undefined) {
175
- this._data[key] = (value: any) => {
176
- r(value)
177
- };
231
+ const state = navigationStore.getSnapshot()
232
+ navigationStore.setState({
233
+ ...state,
234
+ data: {
235
+ ...state.data,
236
+ [key]: (value: any) => {
237
+ r(value)
238
+ }
239
+ }
240
+ })
178
241
  }
179
- doIt(() => {
180
- this.push(replaceModuleByUrlParam(params, route), params)
181
- })
242
+ this.push(replaceModuleByUrlParam(params, route), params)
182
243
  })
183
244
  },
184
245
  /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#replace) untuk melihat dokumentasi*/
@@ -191,14 +252,12 @@ export default {
191
252
  /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#push) untuk melihat dokumentasi*/
192
253
  push<S extends keyof EspArgsInterface>(route: S, params?: EspArgsInterface[S]): void {
193
254
  logArgs(params)
194
- doIt(() => {
195
- this._ref?.dispatch?.(
196
- StackActions.push(
197
- replaceModuleByUrlParam(params, route),
198
- params
199
- )
255
+ this._ref?.dispatch?.(
256
+ StackActions.push(
257
+ replaceModuleByUrlParam(params, route),
258
+ params
200
259
  )
201
- })
260
+ )
202
261
  },
203
262
  /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#reset) untuk melihat dokumentasi*/
204
263
  reset(route?: LibNavigationRoutes, ...routes: LibNavigationRoutes[]): void {
@@ -219,9 +278,7 @@ export default {
219
278
  back(deep?: number): void {
220
279
  let _deep = deep || 1
221
280
  const popAction = StackActions.pop(_deep);
222
- doIt(() => {
223
- this._ref?.dispatch?.(popAction)
224
- })
281
+ this._ref?.dispatch?.(popAction)
225
282
  },
226
283
 
227
284
  /* return `root` on initialRoute otherwise return the route was active */
@@ -244,10 +301,6 @@ export default {
244
301
  }
245
302
  }
246
303
 
247
- function doIt(func: Function) {
248
- requestAnimationFrame(() => func())
249
- }
250
-
251
304
 
252
305
  function replaceModuleByUrlParam<S extends keyof EspArgsInterface>(params: any, defaultModule: S) {
253
306
  let module = defaultModule
@@ -1,3 +1,4 @@
1
+ //[moved] change
1
2
  //noPage
2
3
  import AsyncStorage from '@react-native-async-storage/async-storage';
3
4
  import esp from 'esoftplay/esp';
@@ -5,7 +6,7 @@ import MMKV from 'esoftplay/mmkv';
5
6
  import Storage from 'esoftplay/storage';
6
7
  import * as R from 'react';
7
8
  import isEqual from 'react-fast-compare';
8
- import { createDebounce } from './timeout';
9
+ import { createDebounce } from 'esoftplay/timeout';
9
10
 
10
11
 
11
12
  export interface useGlobalReturn<T> {
@@ -44,7 +45,7 @@ export interface useGlobalConnect<T> {
44
45
  render: (props: Partial<T> | T) => any,
45
46
  }
46
47
  export let userDataReset: Function[] = []
47
- let timeoutFinish: NodeJS.Timeout
48
+ let timeoutFinish: ReturnType<typeof setTimeout>
48
49
 
49
50
  /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/global.md) untuk melihat dokumentasi*/
50
51
  export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): useGlobalReturn<T> {
@@ -54,11 +55,17 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
54
55
  }
55
56
  const STORAGE = o?.inFastStorage ? MMKV : (o?.inFile ? Storage : AsyncStorage);
56
57
  let value: T = initValue;
57
- const subsSetter = new Set<(newValue: T) => void>(); // Typed Set
58
+ const subsSetter = new Set<() => void>(); // Typed Set
58
59
  const listener = new Set<(value: T) => void>(); // Typed Set
59
60
  let loaded = -1;
60
61
  let taskSync: any = undefined;
61
62
 
63
+ const useSyncStore = (R as any).useSyncExternalStore;
64
+ const subscribeStore = (callback: () => void) => {
65
+ subsSetter.add(callback)
66
+ return () => subsSetter.delete(callback)
67
+ }
68
+
62
69
  // Optimization: Check persistKey only once
63
70
  const hasPersistKey = !!o?.persistKey;
64
71
  const persistKey = o?.persistKey; // Store it for easier access
@@ -133,7 +140,7 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
133
140
  } else if (p === "true" || p === "false") {
134
141
  set(JSON.parse(p)); // Directly parse boolean strings
135
142
  } else if (!isNaN(p as any)) {
136
- set(Number(p)); // Directly convert to number
143
+ set((Number(p) as unknown) as T); // Directly convert to number
137
144
  } else {
138
145
  set(p); // No need for eval if not an object or boolean or number
139
146
  }
@@ -180,14 +187,14 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
180
187
 
181
188
  if (!isEqual(value, newValue)) { // Use direct import of isEqual
182
189
  value = newValue;
183
- subsSetter.forEach((c) => c(newValue)); // Directly call the callback
190
+ subsSetter.forEach((c) => c());
184
191
 
185
192
  if (hasPersistKey && newValue !== undefined) { // Check hasPersistKey
186
193
  const data = typeof newValue === 'object' && newValue !== null
187
194
  ? (o.jsonBeautify ? JSON.stringify(newValue, null, 2) : JSON.stringify(newValue))
188
195
  : String(newValue); // Simplified data assignment
189
196
 
190
- STORAGE.setItem(persistKey, data); // Use the stored persistKey
197
+ STORAGE.setItem(String(persistKey), data); // Use the stored persistKey
191
198
  }
192
199
 
193
200
  if (o?.listener) {
@@ -209,26 +216,25 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
209
216
  set(initValue)
210
217
  }
211
218
 
212
- function useSelector(se: (state: T) => any): Partial<T> | T {
219
+ function useSelector(se: (state: T) => any): any {
213
220
  loadFromDisk()
214
221
 
215
- let [l, s] = R.useState<any>(se(value));
222
+ const getSnapshot = () => se(value)
223
+ const subscribe = subscribeStore
216
224
 
217
- let sl = (ns: T) => {
218
- let n = se(ns);
219
- if (!isEqual(l, n))
220
- s(n);
221
- }
225
+ return useSyncStore ? (useSyncStore(subscribe, getSnapshot, getSnapshot)) : R.useMemo(() => se(value), [value])
226
+ }
222
227
 
223
- R.useLayoutEffect(() => {
224
- subsSetter.add(sl)
225
- return () => {
226
- subsSetter.delete(sl)
227
- };
228
- }, [sl]);
228
+ function useState(): [T, (newState: T | ((newState: T) => T)) => void, () => T] {
229
+ loadFromDisk()
229
230
 
230
- return l;
231
- }
231
+ const getSnapshot = () => value
232
+ const subscribe = subscribeStore
233
+
234
+ const state = useSyncStore ? useSyncStore(subscribe, getSnapshot, getSnapshot) : R.useState<T>(value)[0]
235
+
236
+ return [state, set, () => value];
237
+ };
232
238
 
233
239
  function useAutoSyncOnNetworkChanges() {
234
240
  esp.mod("lib/net_status").subscriber.useSubscribe(({ isInternetReachable, isOnline }) => {
@@ -253,21 +259,6 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
253
259
  return out;
254
260
  }
255
261
 
256
-
257
- function useState(): [T, (newState: T | ((newState: T) => T)) => void, () => T] {
258
- loadFromDisk()
259
- let [l, s] = R.useState<T>(value);
260
-
261
- R.useLayoutEffect(() => {
262
- subsSetter.add(s)
263
- return () => {
264
- subsSetter.delete(s)
265
- };
266
- }, [s]);
267
-
268
- return [l, set, () => value];
269
- };
270
-
271
262
  function _connect(props: useGlobalConnect<T>): any {
272
263
  const state = props.selector ? useSelector(props.selector) : useState()[0]
273
264
  const children = props.render(state)
@@ -23,7 +23,7 @@ export default function m(defaultUrl?: string): void {
23
23
  }
24
24
  return url
25
25
  }
26
- new (esp.mod("lib/curl"))().custom(removeLastDot(url) + "&t=" + new Date().getTime(), null,
26
+ new (esp.mod("lib/curl"))().custom(removeLastDot(url) + (removeLastDot(url).includes("?") ? "&" : "?") + "t=" + new Date().getTime(), null,
27
27
  (res) => {
28
28
  if (res.ok == 1) {
29
29
  params.set(res.result.params)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esoftplay",
3
- "version": "0.0.269-beta4d33991",
3
+ "version": "0.0.269-beta6ae30d2",
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",