phecda-react 0.1.0-beta.14 → 0.1.0-beta.16
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 +4 -4
- package/dist/index.js +14 -13
- package/dist/index.mjs +14 -13
- package/package.json +2 -2
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>(
|
|
5
|
-
declare function useR<T extends Construct>(
|
|
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
|
|
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>(
|
|
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(
|
|
37
|
+
function useO(model) {
|
|
38
38
|
const { state, origin } = (0, import_phecda_web.getActiveInstance)();
|
|
39
|
-
if ((0, import_phecda_web.get)(
|
|
40
|
-
const instance2 = new
|
|
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)(
|
|
43
|
+
const tag = (0, import_phecda_web.getTag)(model);
|
|
44
44
|
if (tag in state) {
|
|
45
|
-
if (origin.get(state[tag]) !==
|
|
46
|
-
console.warn(`Synonym module: Module taged "${String(tag)}" has been loaded before, so won't load Module "${
|
|
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
|
|
49
|
+
const instance = new model();
|
|
50
50
|
state[tag] = instance;
|
|
51
51
|
return instance;
|
|
52
52
|
}
|
|
53
53
|
__name(useO, "useO");
|
|
54
|
-
function useR(
|
|
54
|
+
function useR(model) {
|
|
55
55
|
const { cache: cacheMap } = (0, import_phecda_web.getActiveInstance)();
|
|
56
|
-
const instance = useO(
|
|
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
|
-
|
|
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(
|
|
101
|
-
const instance = useO(
|
|
102
|
-
const newInstance = new
|
|
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(
|
|
8
|
+
function useO(model) {
|
|
9
9
|
const { state, origin } = getActiveInstance();
|
|
10
|
-
if (get(
|
|
11
|
-
const instance2 = new
|
|
10
|
+
if (get(model.prototype, "isolate")) {
|
|
11
|
+
const instance2 = new model();
|
|
12
12
|
return instance2;
|
|
13
13
|
}
|
|
14
|
-
const tag = getTag(
|
|
14
|
+
const tag = getTag(model);
|
|
15
15
|
if (tag in state) {
|
|
16
|
-
if (origin.get(state[tag]) !==
|
|
17
|
-
console.warn(`Synonym module: Module taged "${String(tag)}" has been loaded before, so won't load Module "${
|
|
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
|
|
20
|
+
const instance = new model();
|
|
21
21
|
state[tag] = instance;
|
|
22
22
|
return instance;
|
|
23
23
|
}
|
|
24
24
|
__name(useO, "useO");
|
|
25
|
-
function useR(
|
|
25
|
+
function useR(model) {
|
|
26
26
|
const { cache: cacheMap } = getActiveInstance();
|
|
27
|
-
const instance = useO(
|
|
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
|
-
|
|
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(
|
|
72
|
-
const instance = useO(
|
|
73
|
-
const newInstance = new
|
|
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.
|
|
3
|
+
"version": "0.1.0-beta.16",
|
|
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.
|
|
17
|
+
"phecda-web": "1.0.1-beta.12"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@types/react": "^18.2.48",
|