phecda-react 0.1.0-beta.14 → 0.1.0-beta.15

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/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { Construct, Events } from 'phecda-web';
2
2
  export * from 'phecda-web';
3
3
 
4
- declare function useO<T extends Construct>(module: T): any;
5
- declare function useR<T extends Construct>(module: T): [InstanceType<T>, InstanceType<T>];
4
+ declare function useO<T extends Construct>(model: T): any;
5
+ declare function useR<T extends Construct>(model: T): [InstanceType<T>, InstanceType<T>];
6
6
  declare function createPhecda(): {
7
- load(state: any): any;
7
+ load(state?: any): any;
8
8
  unmount(): Promise<void>;
9
9
  };
10
10
  declare function useEvent<Key extends keyof Events>(eventName: Key, cb: (event: Events[Key]) => void): ((arg: Events[Key]) => void)[];
11
- declare function initialize<M extends Construct>(module: M, deleteOtherProperty?: boolean): InstanceType<M> | void;
11
+ declare function initialize<M extends Construct>(model: M, deleteOtherProperty?: boolean): InstanceType<M> | void;
12
12
 
13
13
  export { createPhecda, initialize, useEvent, useO, useR };
package/dist/index.js CHANGED
@@ -34,26 +34,26 @@ module.exports = __toCommonJS(src_exports);
34
34
  var import_valtio = require("valtio");
35
35
  var import_react = require("react");
36
36
  var import_phecda_web = require("phecda-web");
37
- function useO(module2) {
37
+ function useO(model) {
38
38
  const { state, origin } = (0, import_phecda_web.getActiveInstance)();
39
- if ((0, import_phecda_web.get)(module2.prototype, "isolate")) {
40
- const instance2 = new module2();
39
+ if ((0, import_phecda_web.get)(model.prototype, "isolate")) {
40
+ const instance2 = new model();
41
41
  return instance2;
42
42
  }
43
- const tag = (0, import_phecda_web.getTag)(module2);
43
+ const tag = (0, import_phecda_web.getTag)(model);
44
44
  if (tag in state) {
45
- if (origin.get(state[tag]) !== module2)
46
- console.warn(`Synonym module: Module taged "${String(tag)}" has been loaded before, so won't load Module "${module2.name}"`);
45
+ if (origin.get(state[tag]) !== model)
46
+ console.warn(`Synonym module: Module taged "${String(tag)}" has been loaded before, so won't load Module "${model.name}"`);
47
47
  return state[tag];
48
48
  }
49
- const instance = new module2();
49
+ const instance = new model();
50
50
  state[tag] = instance;
51
51
  return instance;
52
52
  }
53
53
  __name(useO, "useO");
54
- function useR(module2) {
54
+ function useR(model) {
55
55
  const { cache: cacheMap } = (0, import_phecda_web.getActiveInstance)();
56
- const instance = useO(module2);
56
+ const instance = useO(model);
57
57
  if (cacheMap.has(instance)) {
58
58
  const proxyInstance2 = cacheMap.get(instance);
59
59
  return [
@@ -75,7 +75,8 @@ function createPhecda() {
75
75
  return {
76
76
  load(state) {
77
77
  const instance = (0, import_phecda_web.getActiveInstance)();
78
- instance.state = state;
78
+ if (state)
79
+ instance.state = state;
79
80
  return this;
80
81
  },
81
82
  async unmount() {
@@ -97,9 +98,9 @@ function useEvent(eventName, cb) {
97
98
  ];
98
99
  }
99
100
  __name(useEvent, "useEvent");
100
- function initialize(module2, deleteOtherProperty = true) {
101
- const instance = useO(module2);
102
- const newInstance = new module2();
101
+ function initialize(model, deleteOtherProperty = true) {
102
+ const instance = useO(model);
103
+ const newInstance = new model();
103
104
  Object.assign(instance, newInstance);
104
105
  if (deleteOtherProperty) {
105
106
  for (const key in instance) {
package/dist/index.mjs CHANGED
@@ -5,26 +5,26 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
5
5
  import { proxy, useSnapshot } from "valtio";
6
6
  import { useEffect } from "react";
7
7
  import { emitter, get, getActiveInstance, getTag, invokeHandler, resetActiveInstance } from "phecda-web";
8
- function useO(module) {
8
+ function useO(model) {
9
9
  const { state, origin } = getActiveInstance();
10
- if (get(module.prototype, "isolate")) {
11
- const instance2 = new module();
10
+ if (get(model.prototype, "isolate")) {
11
+ const instance2 = new model();
12
12
  return instance2;
13
13
  }
14
- const tag = getTag(module);
14
+ const tag = getTag(model);
15
15
  if (tag in state) {
16
- if (origin.get(state[tag]) !== module)
17
- console.warn(`Synonym module: Module taged "${String(tag)}" has been loaded before, so won't load Module "${module.name}"`);
16
+ if (origin.get(state[tag]) !== model)
17
+ console.warn(`Synonym module: Module taged "${String(tag)}" has been loaded before, so won't load Module "${model.name}"`);
18
18
  return state[tag];
19
19
  }
20
- const instance = new module();
20
+ const instance = new model();
21
21
  state[tag] = instance;
22
22
  return instance;
23
23
  }
24
24
  __name(useO, "useO");
25
- function useR(module) {
25
+ function useR(model) {
26
26
  const { cache: cacheMap } = getActiveInstance();
27
- const instance = useO(module);
27
+ const instance = useO(model);
28
28
  if (cacheMap.has(instance)) {
29
29
  const proxyInstance2 = cacheMap.get(instance);
30
30
  return [
@@ -46,7 +46,8 @@ function createPhecda() {
46
46
  return {
47
47
  load(state) {
48
48
  const instance = getActiveInstance();
49
- instance.state = state;
49
+ if (state)
50
+ instance.state = state;
50
51
  return this;
51
52
  },
52
53
  async unmount() {
@@ -68,9 +69,9 @@ function useEvent(eventName, cb) {
68
69
  ];
69
70
  }
70
71
  __name(useEvent, "useEvent");
71
- function initialize(module, deleteOtherProperty = true) {
72
- const instance = useO(module);
73
- const newInstance = new module();
72
+ function initialize(model, deleteOtherProperty = true) {
73
+ const instance = useO(model);
74
+ const newInstance = new model();
74
75
  Object.assign(instance, newInstance);
75
76
  if (deleteOtherProperty) {
76
77
  for (const key in instance) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-react",
3
- "version": "0.1.0-beta.14",
3
+ "version": "0.1.0-beta.15",
4
4
  "description": "provide phecda function to react by valtio",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -14,7 +14,7 @@
14
14
  "dependencies": {
15
15
  "react": "^18.2.0",
16
16
  "valtio": "^1.13.0",
17
- "phecda-web": "1.0.1-beta.10"
17
+ "phecda-web": "1.0.1-beta.11"
18
18
  },
19
19
  "devDependencies": {
20
20
  "@types/react": "^18.2.48",