phecda-web 2.0.0 → 2.0.1
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 +2 -2
- package/dist/index.js +21 -16
- package/dist/index.mjs +21 -16
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -16,11 +16,11 @@ declare function defaultWebInject(): void;
|
|
|
16
16
|
declare function wait(...instances: InstanceType<Construct>[]): Promise<any[]>;
|
|
17
17
|
declare function bindMethod(instance: any): any;
|
|
18
18
|
declare class WebPhecda {
|
|
19
|
-
protected
|
|
19
|
+
protected parseModule: <Instance = any>(instance: Instance) => Instance;
|
|
20
20
|
origin: Record<string, any>;
|
|
21
21
|
state: Record<string | symbol, any>;
|
|
22
22
|
modelMap: WeakMap<object, any>;
|
|
23
|
-
constructor(
|
|
23
|
+
constructor(parseModule: <Instance = any>(instance: Instance) => Instance);
|
|
24
24
|
init<Model extends Construct>(model: Model): InstanceType<Model>;
|
|
25
25
|
patch<Model extends Construct>(model: Model, data: DeepPartial<InstanceType<Model>>): void;
|
|
26
26
|
wait(...modelOrTag: (Construct | PropertyKey)[]): Promise<any[]>;
|
package/dist/index.js
CHANGED
|
@@ -122,32 +122,37 @@ function getParamtypes(Model, key) {
|
|
|
122
122
|
return Reflect.getMetadata("design:paramtypes", Model, key);
|
|
123
123
|
}
|
|
124
124
|
__name(getParamtypes, "getParamtypes");
|
|
125
|
+
var bindCache = /* @__PURE__ */ new WeakMap();
|
|
125
126
|
function bindMethod(instance) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (!
|
|
131
|
-
cache.
|
|
132
|
-
|
|
127
|
+
if (!bindCache.has(instance)) {
|
|
128
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
129
|
+
bindCache.set(instance, new Proxy(instance, {
|
|
130
|
+
get(target, p) {
|
|
131
|
+
if (typeof target[p] === "function" && !target[p].toString().startsWith("(")) {
|
|
132
|
+
if (!cache.has(target[p]))
|
|
133
|
+
cache.set(target[p], target[p].bind(target));
|
|
134
|
+
return cache.get(target[p]);
|
|
135
|
+
}
|
|
136
|
+
return target[p];
|
|
133
137
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
return bindCache.get(instance);
|
|
137
141
|
}
|
|
138
142
|
__name(bindMethod, "bindMethod");
|
|
139
143
|
var WebPhecda = class {
|
|
140
|
-
|
|
144
|
+
parseModule;
|
|
141
145
|
origin;
|
|
142
146
|
state;
|
|
143
147
|
modelMap;
|
|
144
|
-
constructor(
|
|
145
|
-
this.
|
|
148
|
+
constructor(parseModule) {
|
|
149
|
+
this.parseModule = parseModule;
|
|
146
150
|
this.origin = {};
|
|
147
151
|
this.state = {};
|
|
148
152
|
this.modelMap = /* @__PURE__ */ new WeakMap();
|
|
149
153
|
defaultWebInject();
|
|
150
154
|
}
|
|
155
|
+
// Initialize a module that has not been created yet, and return it directly if it is cached.
|
|
151
156
|
init(model) {
|
|
152
157
|
const tag = (0, import_phecda_core2.getTag)(model);
|
|
153
158
|
const initModel = /* @__PURE__ */ __name(() => {
|
|
@@ -157,9 +162,9 @@ var WebPhecda = class {
|
|
|
157
162
|
const paramtypesInstances = [];
|
|
158
163
|
for (const i in paramtypes)
|
|
159
164
|
paramtypesInstances[i] = this.init(paramtypes[i]);
|
|
160
|
-
instance2 = this.
|
|
165
|
+
instance2 = this.parseModule(new model(...paramtypesInstances));
|
|
161
166
|
} else {
|
|
162
|
-
instance2 = this.
|
|
167
|
+
instance2 = this.parseModule(new model());
|
|
163
168
|
}
|
|
164
169
|
if (tag in this.origin) {
|
|
165
170
|
Object.assign(instance2, this.origin[tag]);
|
|
@@ -167,7 +172,7 @@ var WebPhecda = class {
|
|
|
167
172
|
}
|
|
168
173
|
if (typeof window !== "undefined")
|
|
169
174
|
instance2._promise = (0, import_phecda_core2.invokeHandler)("init", instance2);
|
|
170
|
-
return
|
|
175
|
+
return instance2;
|
|
171
176
|
}, "initModel");
|
|
172
177
|
const { state, modelMap: map } = this;
|
|
173
178
|
if ((0, import_phecda_core2.get)(model.prototype, "isolate"))
|
package/dist/index.mjs
CHANGED
|
@@ -84,32 +84,37 @@ function getParamtypes(Model, key) {
|
|
|
84
84
|
return Reflect.getMetadata("design:paramtypes", Model, key);
|
|
85
85
|
}
|
|
86
86
|
__name(getParamtypes, "getParamtypes");
|
|
87
|
+
var bindCache = /* @__PURE__ */ new WeakMap();
|
|
87
88
|
function bindMethod(instance) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (!
|
|
93
|
-
cache.
|
|
94
|
-
|
|
89
|
+
if (!bindCache.has(instance)) {
|
|
90
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
91
|
+
bindCache.set(instance, new Proxy(instance, {
|
|
92
|
+
get(target, p) {
|
|
93
|
+
if (typeof target[p] === "function" && !target[p].toString().startsWith("(")) {
|
|
94
|
+
if (!cache.has(target[p]))
|
|
95
|
+
cache.set(target[p], target[p].bind(target));
|
|
96
|
+
return cache.get(target[p]);
|
|
97
|
+
}
|
|
98
|
+
return target[p];
|
|
95
99
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
return bindCache.get(instance);
|
|
99
103
|
}
|
|
100
104
|
__name(bindMethod, "bindMethod");
|
|
101
105
|
var WebPhecda = class {
|
|
102
|
-
|
|
106
|
+
parseModule;
|
|
103
107
|
origin;
|
|
104
108
|
state;
|
|
105
109
|
modelMap;
|
|
106
|
-
constructor(
|
|
107
|
-
this.
|
|
110
|
+
constructor(parseModule) {
|
|
111
|
+
this.parseModule = parseModule;
|
|
108
112
|
this.origin = {};
|
|
109
113
|
this.state = {};
|
|
110
114
|
this.modelMap = /* @__PURE__ */ new WeakMap();
|
|
111
115
|
defaultWebInject();
|
|
112
116
|
}
|
|
117
|
+
// Initialize a module that has not been created yet, and return it directly if it is cached.
|
|
113
118
|
init(model) {
|
|
114
119
|
const tag = getTag(model);
|
|
115
120
|
const initModel = /* @__PURE__ */ __name(() => {
|
|
@@ -119,9 +124,9 @@ var WebPhecda = class {
|
|
|
119
124
|
const paramtypesInstances = [];
|
|
120
125
|
for (const i in paramtypes)
|
|
121
126
|
paramtypesInstances[i] = this.init(paramtypes[i]);
|
|
122
|
-
instance2 = this.
|
|
127
|
+
instance2 = this.parseModule(new model(...paramtypesInstances));
|
|
123
128
|
} else {
|
|
124
|
-
instance2 = this.
|
|
129
|
+
instance2 = this.parseModule(new model());
|
|
125
130
|
}
|
|
126
131
|
if (tag in this.origin) {
|
|
127
132
|
Object.assign(instance2, this.origin[tag]);
|
|
@@ -129,7 +134,7 @@ var WebPhecda = class {
|
|
|
129
134
|
}
|
|
130
135
|
if (typeof window !== "undefined")
|
|
131
136
|
instance2._promise = invokeHandler("init", instance2);
|
|
132
|
-
return
|
|
137
|
+
return instance2;
|
|
133
138
|
}, "initModel");
|
|
134
139
|
const { state, modelMap: map } = this;
|
|
135
140
|
if (get(model.prototype, "isolate"))
|