phecda-web 2.0.0 → 2.0.2
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/README.md +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.js +39 -20
- package/dist/index.mjs +37 -20
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -14,13 +14,15 @@ declare const emitter: PhecdaEmitter;
|
|
|
14
14
|
declare function defaultWebInject(): void;
|
|
15
15
|
|
|
16
16
|
declare function wait(...instances: InstanceType<Construct>[]): Promise<any[]>;
|
|
17
|
+
declare function setDefaultPhecda(phecda: WebPhecda): void;
|
|
18
|
+
declare function getDefaultPhecda(): WebPhecda;
|
|
17
19
|
declare function bindMethod(instance: any): any;
|
|
18
20
|
declare class WebPhecda {
|
|
19
|
-
protected
|
|
21
|
+
protected parseModule: <Instance = any>(instance: Instance) => Instance;
|
|
20
22
|
origin: Record<string, any>;
|
|
21
23
|
state: Record<string | symbol, any>;
|
|
22
24
|
modelMap: WeakMap<object, any>;
|
|
23
|
-
constructor(
|
|
25
|
+
constructor(parseModule: <Instance = any>(instance: Instance) => Instance);
|
|
24
26
|
init<Model extends Construct>(model: Model): InstanceType<Model>;
|
|
25
27
|
patch<Model extends Construct>(model: Model, data: DeepPartial<InstanceType<Model>>): void;
|
|
26
28
|
wait(...modelOrTag: (Construct | PropertyKey)[]): Promise<any[]>;
|
|
@@ -46,4 +48,4 @@ declare class Base {
|
|
|
46
48
|
private _unmount;
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
export { Base, DeepPartial, PhecdaEmitter, WebPhecda, bindMethod, defaultWebInject, emitter, wait };
|
|
51
|
+
export { Base, DeepPartial, PhecdaEmitter, WebPhecda, bindMethod, defaultWebInject, emitter, getDefaultPhecda, setDefaultPhecda, wait };
|
package/dist/index.js
CHANGED
|
@@ -37,18 +37,18 @@ __export(src_exports, {
|
|
|
37
37
|
bindMethod: () => bindMethod,
|
|
38
38
|
defaultWebInject: () => defaultWebInject,
|
|
39
39
|
emitter: () => emitter,
|
|
40
|
+
getDefaultPhecda: () => getDefaultPhecda,
|
|
41
|
+
setDefaultPhecda: () => setDefaultPhecda,
|
|
40
42
|
wait: () => wait
|
|
41
43
|
});
|
|
42
44
|
module.exports = __toCommonJS(src_exports);
|
|
43
45
|
__reExport(src_exports, require("phecda-core"), module.exports);
|
|
44
46
|
|
|
45
|
-
// src/
|
|
47
|
+
// src/inject.ts
|
|
46
48
|
var import_phecda_core = require("phecda-core");
|
|
47
49
|
var import_mitt = __toESM(require("mitt"));
|
|
48
50
|
var emitter = (0, import_mitt.default)();
|
|
49
51
|
function defaultWebInject() {
|
|
50
|
-
if (typeof window === "undefined")
|
|
51
|
-
return;
|
|
52
52
|
if (!(0, import_phecda_core.getInject)("watcher")) {
|
|
53
53
|
(0, import_phecda_core.setInject)("watcher", ({ eventName, instance, key, options }) => {
|
|
54
54
|
const fn = typeof instance[key] === "function" ? instance[key].bind(instance) : (v) => instance[key] = v;
|
|
@@ -122,32 +122,49 @@ function getParamtypes(Model, key) {
|
|
|
122
122
|
return Reflect.getMetadata("design:paramtypes", Model, key);
|
|
123
123
|
}
|
|
124
124
|
__name(getParamtypes, "getParamtypes");
|
|
125
|
+
var defaultPhecda;
|
|
126
|
+
function setDefaultPhecda(phecda) {
|
|
127
|
+
defaultPhecda = phecda;
|
|
128
|
+
}
|
|
129
|
+
__name(setDefaultPhecda, "setDefaultPhecda");
|
|
130
|
+
function getDefaultPhecda() {
|
|
131
|
+
return defaultPhecda;
|
|
132
|
+
}
|
|
133
|
+
__name(getDefaultPhecda, "getDefaultPhecda");
|
|
134
|
+
var bindCache = /* @__PURE__ */ new WeakMap();
|
|
125
135
|
function bindMethod(instance) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (!
|
|
131
|
-
cache.
|
|
132
|
-
|
|
136
|
+
if (!bindCache.has(instance)) {
|
|
137
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
138
|
+
bindCache.set(instance, new Proxy(instance, {
|
|
139
|
+
get(target, p) {
|
|
140
|
+
if (typeof target[p] === "function" && !target[p].toString().startsWith("(")) {
|
|
141
|
+
if (!cache.has(target[p]))
|
|
142
|
+
cache.set(target[p], target[p].bind(target));
|
|
143
|
+
return cache.get(target[p]);
|
|
144
|
+
}
|
|
145
|
+
return target[p];
|
|
133
146
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
147
|
+
}));
|
|
148
|
+
}
|
|
149
|
+
return bindCache.get(instance);
|
|
137
150
|
}
|
|
138
151
|
__name(bindMethod, "bindMethod");
|
|
139
152
|
var WebPhecda = class {
|
|
140
|
-
|
|
153
|
+
parseModule;
|
|
141
154
|
origin;
|
|
142
155
|
state;
|
|
143
156
|
modelMap;
|
|
144
|
-
constructor(
|
|
145
|
-
this.
|
|
157
|
+
constructor(parseModule) {
|
|
158
|
+
this.parseModule = parseModule;
|
|
146
159
|
this.origin = {};
|
|
147
160
|
this.state = {};
|
|
148
161
|
this.modelMap = /* @__PURE__ */ new WeakMap();
|
|
149
|
-
|
|
162
|
+
if (typeof window !== "undefined") {
|
|
163
|
+
defaultWebInject();
|
|
164
|
+
setDefaultPhecda(this);
|
|
165
|
+
}
|
|
150
166
|
}
|
|
167
|
+
// Initialize a module that has not been created yet, and return it directly if it is cached.
|
|
151
168
|
init(model) {
|
|
152
169
|
const tag = (0, import_phecda_core2.getTag)(model);
|
|
153
170
|
const initModel = /* @__PURE__ */ __name(() => {
|
|
@@ -157,9 +174,9 @@ var WebPhecda = class {
|
|
|
157
174
|
const paramtypesInstances = [];
|
|
158
175
|
for (const i in paramtypes)
|
|
159
176
|
paramtypesInstances[i] = this.init(paramtypes[i]);
|
|
160
|
-
instance2 = this.
|
|
177
|
+
instance2 = this.parseModule(new model(...paramtypesInstances));
|
|
161
178
|
} else {
|
|
162
|
-
instance2 = this.
|
|
179
|
+
instance2 = this.parseModule(new model());
|
|
163
180
|
}
|
|
164
181
|
if (tag in this.origin) {
|
|
165
182
|
Object.assign(instance2, this.origin[tag]);
|
|
@@ -167,7 +184,7 @@ var WebPhecda = class {
|
|
|
167
184
|
}
|
|
168
185
|
if (typeof window !== "undefined")
|
|
169
186
|
instance2._promise = (0, import_phecda_core2.invokeHandler)("init", instance2);
|
|
170
|
-
return
|
|
187
|
+
return instance2;
|
|
171
188
|
}, "initModel");
|
|
172
189
|
const { state, modelMap: map } = this;
|
|
173
190
|
if ((0, import_phecda_core2.get)(model.prototype, "isolate"))
|
|
@@ -310,6 +327,8 @@ _ts_decorate([
|
|
|
310
327
|
bindMethod,
|
|
311
328
|
defaultWebInject,
|
|
312
329
|
emitter,
|
|
330
|
+
getDefaultPhecda,
|
|
331
|
+
setDefaultPhecda,
|
|
313
332
|
wait,
|
|
314
333
|
...require("phecda-core")
|
|
315
334
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -4,13 +4,11 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
4
4
|
// src/index.ts
|
|
5
5
|
export * from "phecda-core";
|
|
6
6
|
|
|
7
|
-
// src/
|
|
7
|
+
// src/inject.ts
|
|
8
8
|
import { getInject, setInject } from "phecda-core";
|
|
9
9
|
import mitt from "mitt";
|
|
10
10
|
var emitter = mitt();
|
|
11
11
|
function defaultWebInject() {
|
|
12
|
-
if (typeof window === "undefined")
|
|
13
|
-
return;
|
|
14
12
|
if (!getInject("watcher")) {
|
|
15
13
|
setInject("watcher", ({ eventName, instance, key, options }) => {
|
|
16
14
|
const fn = typeof instance[key] === "function" ? instance[key].bind(instance) : (v) => instance[key] = v;
|
|
@@ -84,32 +82,49 @@ function getParamtypes(Model, key) {
|
|
|
84
82
|
return Reflect.getMetadata("design:paramtypes", Model, key);
|
|
85
83
|
}
|
|
86
84
|
__name(getParamtypes, "getParamtypes");
|
|
85
|
+
var defaultPhecda;
|
|
86
|
+
function setDefaultPhecda(phecda) {
|
|
87
|
+
defaultPhecda = phecda;
|
|
88
|
+
}
|
|
89
|
+
__name(setDefaultPhecda, "setDefaultPhecda");
|
|
90
|
+
function getDefaultPhecda() {
|
|
91
|
+
return defaultPhecda;
|
|
92
|
+
}
|
|
93
|
+
__name(getDefaultPhecda, "getDefaultPhecda");
|
|
94
|
+
var bindCache = /* @__PURE__ */ new WeakMap();
|
|
87
95
|
function bindMethod(instance) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (!
|
|
93
|
-
cache.
|
|
94
|
-
|
|
96
|
+
if (!bindCache.has(instance)) {
|
|
97
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
98
|
+
bindCache.set(instance, new Proxy(instance, {
|
|
99
|
+
get(target, p) {
|
|
100
|
+
if (typeof target[p] === "function" && !target[p].toString().startsWith("(")) {
|
|
101
|
+
if (!cache.has(target[p]))
|
|
102
|
+
cache.set(target[p], target[p].bind(target));
|
|
103
|
+
return cache.get(target[p]);
|
|
104
|
+
}
|
|
105
|
+
return target[p];
|
|
95
106
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
return bindCache.get(instance);
|
|
99
110
|
}
|
|
100
111
|
__name(bindMethod, "bindMethod");
|
|
101
112
|
var WebPhecda = class {
|
|
102
|
-
|
|
113
|
+
parseModule;
|
|
103
114
|
origin;
|
|
104
115
|
state;
|
|
105
116
|
modelMap;
|
|
106
|
-
constructor(
|
|
107
|
-
this.
|
|
117
|
+
constructor(parseModule) {
|
|
118
|
+
this.parseModule = parseModule;
|
|
108
119
|
this.origin = {};
|
|
109
120
|
this.state = {};
|
|
110
121
|
this.modelMap = /* @__PURE__ */ new WeakMap();
|
|
111
|
-
|
|
122
|
+
if (typeof window !== "undefined") {
|
|
123
|
+
defaultWebInject();
|
|
124
|
+
setDefaultPhecda(this);
|
|
125
|
+
}
|
|
112
126
|
}
|
|
127
|
+
// Initialize a module that has not been created yet, and return it directly if it is cached.
|
|
113
128
|
init(model) {
|
|
114
129
|
const tag = getTag(model);
|
|
115
130
|
const initModel = /* @__PURE__ */ __name(() => {
|
|
@@ -119,9 +134,9 @@ var WebPhecda = class {
|
|
|
119
134
|
const paramtypesInstances = [];
|
|
120
135
|
for (const i in paramtypes)
|
|
121
136
|
paramtypesInstances[i] = this.init(paramtypes[i]);
|
|
122
|
-
instance2 = this.
|
|
137
|
+
instance2 = this.parseModule(new model(...paramtypesInstances));
|
|
123
138
|
} else {
|
|
124
|
-
instance2 = this.
|
|
139
|
+
instance2 = this.parseModule(new model());
|
|
125
140
|
}
|
|
126
141
|
if (tag in this.origin) {
|
|
127
142
|
Object.assign(instance2, this.origin[tag]);
|
|
@@ -129,7 +144,7 @@ var WebPhecda = class {
|
|
|
129
144
|
}
|
|
130
145
|
if (typeof window !== "undefined")
|
|
131
146
|
instance2._promise = invokeHandler("init", instance2);
|
|
132
|
-
return
|
|
147
|
+
return instance2;
|
|
133
148
|
}, "initModel");
|
|
134
149
|
const { state, modelMap: map } = this;
|
|
135
150
|
if (get(model.prototype, "isolate"))
|
|
@@ -271,5 +286,7 @@ export {
|
|
|
271
286
|
bindMethod,
|
|
272
287
|
defaultWebInject,
|
|
273
288
|
emitter,
|
|
289
|
+
getDefaultPhecda,
|
|
290
|
+
setDefaultPhecda,
|
|
274
291
|
wait
|
|
275
292
|
};
|