esoftplay 0.0.118-a → 0.0.118-e

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/_cache.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import AsyncStorage from '@react-native-async-storage/async-storage';
2
+ import Storage from 'esoftplay/storage';
2
3
  import * as R from 'react';
3
4
  import { fastFilter, fastLoop } from './fast';
4
5
  const isEqual = require('react-fast-compare');
@@ -11,21 +12,22 @@ export interface UseCache_return<T> {
11
12
 
12
13
  export interface UseCache_options {
13
14
  persistKey?: string,
15
+ inFile?: boolean,
14
16
  listener?: (data: any) => void
15
17
  }
16
18
  export default (() => {
17
19
  let useCacheIdx = 0
18
- let useCacheSubscriber = []
19
- let value = []
20
+ let useCacheSubscriber: any[] = []
20
21
  return <T>(initValue: T, o?: UseCache_options): UseCache_return<T> => {
22
+ const STORAGE = o?.inFile ? new Storage() : AsyncStorage
21
23
  const _idx = useCacheIdx
22
24
  if (!useCacheSubscriber[_idx]) {
23
25
  useCacheSubscriber[_idx] = [];
24
26
  }
25
- value[_idx] = initValue
27
+ let value = initValue
26
28
  // rehidryte instant
27
29
  if (o?.persistKey) {
28
- AsyncStorage.getItem(o.persistKey).then((p) => {
30
+ STORAGE.getItem(o.persistKey).then((p) => {
29
31
  if (p)
30
32
  set(JSON.parse(p))
31
33
  })
@@ -33,14 +35,14 @@ export default (() => {
33
35
 
34
36
  function set(ns: T | ((x: T) => T)) {
35
37
  let isChange = false
36
- if (!isEqual(value[_idx], ns)) {
38
+ if (!isEqual(value, ns)) {
37
39
  isChange = true
38
40
  }
39
41
  if (isChange) {
40
- value[_idx] = ns instanceof Function ? ns(value[_idx]) : ns
41
- fastLoop(useCacheSubscriber[_idx], (c: any) => c?.(value[_idx]))
42
+ value = ns instanceof Function ? ns(value) : ns
43
+ fastLoop(useCacheSubscriber[_idx], (c: any) => c?.(value))
42
44
  if (o?.persistKey) {
43
- AsyncStorage.setItem(o.persistKey, JSON.stringify(value[_idx]))
45
+ STORAGE.setItem(o.persistKey, JSON.stringify(value))
44
46
  }
45
47
  if (o?.listener) {
46
48
  o?.listener?.(ns instanceof Function ? ns(value[_idx]) : ns)
@@ -50,7 +52,7 @@ export default (() => {
50
52
 
51
53
  function del() {
52
54
  if (o?.persistKey) {
53
- AsyncStorage.removeItem(o.persistKey)
55
+ STORAGE.removeItem(o.persistKey)
54
56
  }
55
57
  set(initValue)
56
58
  }
package/bin/router.js CHANGED
@@ -397,6 +397,7 @@ declare module "esoftplay" {
397
397
  function config(param?: string, ...params: string[]): any;
398
398
  function _config(): string | number | boolean;
399
399
  function mod(path: string): any;
400
+ function modProp(path: string): any;
400
401
  function reducer(): any;
401
402
  function versionName(): string;
402
403
  function navigations(): any;
@@ -445,6 +446,7 @@ declare module "esoftplay" {
445
446
  }
446
447
  interface createCacheOption {
447
448
  persistKey?: string,
449
+ inFile?: boolean,
448
450
  listener?: (s:any)=> void
449
451
  }
450
452
  interface createCacheReturn<T> {
@@ -630,11 +632,11 @@ function createRouter() {
630
632
  });
631
633
 
632
634
  let Props = 'function properties(modtask) {' + "\n\t" +
633
- 'var let = {}' + "\n\t" +
635
+ 'var out = {}' + "\n\t" +
634
636
  'switch (modtask) {' + "\n" +
635
637
  TaskProperty + "\t" +
636
638
  '}' + "\n\t" +
637
- 'return let;' + "\n" +
639
+ 'return out;' + "\n" +
638
640
  '}' + "\n" +
639
641
  'module.exports = properties;';
640
642
  if (isChange(tmpDir + "properties.js", Props)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esoftplay",
3
- "version": "0.0.118-a",
3
+ "version": "0.0.118-e",
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",