phecda-react 0.1.0-alpha.8 → 0.1.0-beta.14
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.js +14 -34
- package/dist/index.mjs +11 -31
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -35,14 +35,14 @@ var import_valtio = require("valtio");
|
|
|
35
35
|
var import_react = require("react");
|
|
36
36
|
var import_phecda_web = require("phecda-web");
|
|
37
37
|
function useO(module2) {
|
|
38
|
-
const { state,
|
|
39
|
-
if (module2.prototype
|
|
38
|
+
const { state, origin } = (0, import_phecda_web.getActiveInstance)();
|
|
39
|
+
if ((0, import_phecda_web.get)(module2.prototype, "isolate")) {
|
|
40
40
|
const instance2 = new module2();
|
|
41
41
|
return instance2;
|
|
42
42
|
}
|
|
43
43
|
const tag = (0, import_phecda_web.getTag)(module2);
|
|
44
44
|
if (tag in state) {
|
|
45
|
-
if (
|
|
45
|
+
if (origin.get(state[tag]) !== module2)
|
|
46
46
|
console.warn(`Synonym module: Module taged "${String(tag)}" has been loaded before, so won't load Module "${module2.name}"`);
|
|
47
47
|
return state[tag];
|
|
48
48
|
}
|
|
@@ -52,38 +52,18 @@ function useO(module2) {
|
|
|
52
52
|
}
|
|
53
53
|
__name(useO, "useO");
|
|
54
54
|
function useR(module2) {
|
|
55
|
-
const {
|
|
55
|
+
const { cache: cacheMap } = (0, import_phecda_web.getActiveInstance)();
|
|
56
56
|
const instance = useO(module2);
|
|
57
|
-
if (
|
|
58
|
-
const proxyInstance2 =
|
|
57
|
+
if (cacheMap.has(instance)) {
|
|
58
|
+
const proxyInstance2 = cacheMap.get(instance);
|
|
59
59
|
return [
|
|
60
60
|
(0, import_valtio.useSnapshot)(proxyInstance2),
|
|
61
61
|
proxyInstance2
|
|
62
62
|
];
|
|
63
63
|
}
|
|
64
|
-
const proxyInstance = (0, import_valtio.proxy)(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return target[key];
|
|
68
|
-
if (typeof target[key] === "function") {
|
|
69
|
-
if (fmap.has(target[key]))
|
|
70
|
-
return fmap.get(target[key]);
|
|
71
|
-
const errorHandler = (0, import_phecda_web.getHandler)(target, key).find((item) => item.error)?.error;
|
|
72
|
-
if (!errorHandler)
|
|
73
|
-
return target[key].bind(target);
|
|
74
|
-
const wrapper = (0, import_phecda_web.wrapError)(target, key, errorHandler);
|
|
75
|
-
fmap.set(target[key], wrapper);
|
|
76
|
-
return wrapper;
|
|
77
|
-
}
|
|
78
|
-
return target[key];
|
|
79
|
-
},
|
|
80
|
-
set(target, key, v) {
|
|
81
|
-
target[key] = v;
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
}));
|
|
85
|
-
instance._promise = (0, import_phecda_web.registerSerial)(proxyInstance);
|
|
86
|
-
rmap.set(instance, proxyInstance);
|
|
64
|
+
const proxyInstance = (0, import_valtio.proxy)(instance);
|
|
65
|
+
instance._promise = (0, import_phecda_web.invokeHandler)("init", proxyInstance);
|
|
66
|
+
cacheMap.set(instance, proxyInstance);
|
|
87
67
|
return [
|
|
88
68
|
(0, import_valtio.useSnapshot)(proxyInstance),
|
|
89
69
|
proxyInstance
|
|
@@ -100,7 +80,7 @@ function createPhecda() {
|
|
|
100
80
|
},
|
|
101
81
|
async unmount() {
|
|
102
82
|
const { state } = (0, import_phecda_web.getActiveInstance)();
|
|
103
|
-
await Object.values(state).map((ins) => (0, import_phecda_web.
|
|
83
|
+
await Object.values(state).map((ins) => (0, import_phecda_web.invokeHandler)("unmount", ins));
|
|
104
84
|
(0, import_phecda_web.resetActiveInstance)();
|
|
105
85
|
}
|
|
106
86
|
};
|
|
@@ -108,12 +88,12 @@ function createPhecda() {
|
|
|
108
88
|
__name(createPhecda, "createPhecda");
|
|
109
89
|
function useEvent(eventName, cb) {
|
|
110
90
|
(0, import_react.useEffect)(() => {
|
|
111
|
-
return () => emitter.off(eventName, cb);
|
|
91
|
+
return () => import_phecda_web.emitter.off(eventName, cb);
|
|
112
92
|
});
|
|
113
|
-
emitter.on(eventName, cb);
|
|
93
|
+
import_phecda_web.emitter.on(eventName, cb);
|
|
114
94
|
return [
|
|
115
|
-
(arg) => emitter.emit(eventName, arg),
|
|
116
|
-
() => emitter.off(eventName, cb)
|
|
95
|
+
(arg) => import_phecda_web.emitter.emit(eventName, arg),
|
|
96
|
+
() => import_phecda_web.emitter.off(eventName, cb)
|
|
117
97
|
];
|
|
118
98
|
}
|
|
119
99
|
__name(useEvent, "useEvent");
|
package/dist/index.mjs
CHANGED
|
@@ -4,16 +4,16 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
4
4
|
// src/core.ts
|
|
5
5
|
import { proxy, useSnapshot } from "valtio";
|
|
6
6
|
import { useEffect } from "react";
|
|
7
|
-
import {
|
|
7
|
+
import { emitter, get, getActiveInstance, getTag, invokeHandler, resetActiveInstance } from "phecda-web";
|
|
8
8
|
function useO(module) {
|
|
9
|
-
const { state,
|
|
10
|
-
if (module.prototype
|
|
9
|
+
const { state, origin } = getActiveInstance();
|
|
10
|
+
if (get(module.prototype, "isolate")) {
|
|
11
11
|
const instance2 = new module();
|
|
12
12
|
return instance2;
|
|
13
13
|
}
|
|
14
14
|
const tag = getTag(module);
|
|
15
15
|
if (tag in state) {
|
|
16
|
-
if (
|
|
16
|
+
if (origin.get(state[tag]) !== module)
|
|
17
17
|
console.warn(`Synonym module: Module taged "${String(tag)}" has been loaded before, so won't load Module "${module.name}"`);
|
|
18
18
|
return state[tag];
|
|
19
19
|
}
|
|
@@ -23,38 +23,18 @@ function useO(module) {
|
|
|
23
23
|
}
|
|
24
24
|
__name(useO, "useO");
|
|
25
25
|
function useR(module) {
|
|
26
|
-
const {
|
|
26
|
+
const { cache: cacheMap } = getActiveInstance();
|
|
27
27
|
const instance = useO(module);
|
|
28
|
-
if (
|
|
29
|
-
const proxyInstance2 =
|
|
28
|
+
if (cacheMap.has(instance)) {
|
|
29
|
+
const proxyInstance2 = cacheMap.get(instance);
|
|
30
30
|
return [
|
|
31
31
|
useSnapshot(proxyInstance2),
|
|
32
32
|
proxyInstance2
|
|
33
33
|
];
|
|
34
34
|
}
|
|
35
|
-
const proxyInstance = proxy(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return target[key];
|
|
39
|
-
if (typeof target[key] === "function") {
|
|
40
|
-
if (fmap.has(target[key]))
|
|
41
|
-
return fmap.get(target[key]);
|
|
42
|
-
const errorHandler = getHandler(target, key).find((item) => item.error)?.error;
|
|
43
|
-
if (!errorHandler)
|
|
44
|
-
return target[key].bind(target);
|
|
45
|
-
const wrapper = wrapError(target, key, errorHandler);
|
|
46
|
-
fmap.set(target[key], wrapper);
|
|
47
|
-
return wrapper;
|
|
48
|
-
}
|
|
49
|
-
return target[key];
|
|
50
|
-
},
|
|
51
|
-
set(target, key, v) {
|
|
52
|
-
target[key] = v;
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
}));
|
|
56
|
-
instance._promise = registerSerial(proxyInstance);
|
|
57
|
-
rmap.set(instance, proxyInstance);
|
|
35
|
+
const proxyInstance = proxy(instance);
|
|
36
|
+
instance._promise = invokeHandler("init", proxyInstance);
|
|
37
|
+
cacheMap.set(instance, proxyInstance);
|
|
58
38
|
return [
|
|
59
39
|
useSnapshot(proxyInstance),
|
|
60
40
|
proxyInstance
|
|
@@ -71,7 +51,7 @@ function createPhecda() {
|
|
|
71
51
|
},
|
|
72
52
|
async unmount() {
|
|
73
53
|
const { state } = getActiveInstance();
|
|
74
|
-
await Object.values(state).map((ins) =>
|
|
54
|
+
await Object.values(state).map((ins) => invokeHandler("unmount", ins));
|
|
75
55
|
resetActiveInstance();
|
|
76
56
|
}
|
|
77
57
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phecda-react",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-beta.14",
|
|
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-
|
|
17
|
+
"phecda-web": "1.0.1-beta.10"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@types/react": "^18.2.48",
|