phecda-core 2.1.2-alpha.0 → 3.0.0-alpha.10
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 +65 -47
- package/dist/index.js +190 -200
- package/dist/index.mjs +182 -191
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -33,12 +33,16 @@ __export(src_exports, {
|
|
|
33
33
|
Ignore: () => Ignore,
|
|
34
34
|
Init: () => Init,
|
|
35
35
|
Inject: () => Inject,
|
|
36
|
+
Isolate: () => Isolate,
|
|
36
37
|
Nested: () => Nested,
|
|
37
38
|
Pipeline: () => Pipeline,
|
|
38
39
|
Provide: () => Provide,
|
|
40
|
+
SHARE_KEY: () => SHARE_KEY,
|
|
39
41
|
Storage: () => Storage,
|
|
40
42
|
Tag: () => Tag,
|
|
41
43
|
To: () => To,
|
|
44
|
+
Unique: () => Unique,
|
|
45
|
+
Unmount: () => Unmount,
|
|
42
46
|
Watcher: () => Watcher,
|
|
43
47
|
activeInstance: () => activeInstance,
|
|
44
48
|
addDecoToClass: () => addDecoToClass,
|
|
@@ -46,49 +50,43 @@ __export(src_exports, {
|
|
|
46
50
|
getBind: () => getBind,
|
|
47
51
|
getExposeKey: () => getExposeKey,
|
|
48
52
|
getHandler: () => getHandler,
|
|
49
|
-
|
|
50
|
-
getModelState: () => getModelState,
|
|
53
|
+
getModuleState: () => getModuleState,
|
|
51
54
|
getOwnExposeKey: () => getOwnExposeKey,
|
|
52
55
|
getOwnHandler: () => getOwnHandler,
|
|
53
56
|
getOwnIgnoreKey: () => getOwnIgnoreKey,
|
|
54
|
-
|
|
55
|
-
getOwnModelState: () => getOwnModelState,
|
|
57
|
+
getOwnModuleState: () => getOwnModuleState,
|
|
56
58
|
getOwnState: () => getOwnState,
|
|
57
59
|
getProperty: () => getProperty,
|
|
58
60
|
getState: () => getState,
|
|
59
|
-
|
|
60
|
-
getTag: () => getTag,
|
|
61
|
+
getTag: () => getTag2,
|
|
61
62
|
init: () => init,
|
|
62
63
|
injectProperty: () => injectProperty,
|
|
64
|
+
invokeHandler: () => invokeHandler,
|
|
63
65
|
isPhecda: () => isPhecda,
|
|
64
66
|
plainToClass: () => plainToClass,
|
|
65
67
|
regisHandler: () => regisHandler,
|
|
66
|
-
regisInitEvent: () => regisInitEvent,
|
|
67
|
-
register: () => register,
|
|
68
|
-
registerAsync: () => registerAsync,
|
|
69
68
|
setExposeKey: () => setExposeKey,
|
|
70
69
|
setIgnoreKey: () => setIgnoreKey,
|
|
71
|
-
setModelVar: () => setModelVar,
|
|
72
70
|
setState: () => setState,
|
|
71
|
+
setVar: () => setVar,
|
|
73
72
|
snapShot: () => snapShot,
|
|
74
73
|
transformClass: () => transformClass
|
|
75
74
|
});
|
|
76
75
|
module.exports = __toCommonJS(src_exports);
|
|
77
76
|
|
|
78
77
|
// src/core.ts
|
|
79
|
-
function isPhecda(
|
|
80
|
-
if (typeof
|
|
81
|
-
return !!
|
|
82
|
-
}
|
|
78
|
+
function isPhecda(module2) {
|
|
79
|
+
if (typeof module2 === "function")
|
|
80
|
+
return !!module2.prototype?._namespace;
|
|
83
81
|
return false;
|
|
84
82
|
}
|
|
85
83
|
__name(isPhecda, "isPhecda");
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
var SHARE_KEY = Symbol("phecda-core");
|
|
85
|
+
function init(proto) {
|
|
86
|
+
if (!proto)
|
|
88
87
|
return;
|
|
89
|
-
if (!
|
|
90
|
-
|
|
91
|
-
__INIT_EVENT__: /* @__PURE__ */ new Set(),
|
|
88
|
+
if (!proto.hasOwnProperty("_namespace")) {
|
|
89
|
+
proto._namespace = {
|
|
92
90
|
__EXPOSE_VAR__: /* @__PURE__ */ new Set(),
|
|
93
91
|
__IGNORE_VAR__: /* @__PURE__ */ new Set(),
|
|
94
92
|
__STATE_VAR__: /* @__PURE__ */ new Set(),
|
|
@@ -98,56 +96,31 @@ function init(target) {
|
|
|
98
96
|
}
|
|
99
97
|
}
|
|
100
98
|
__name(init, "init");
|
|
101
|
-
function
|
|
102
|
-
init(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
__name(regisInitEvent, "regisInitEvent");
|
|
106
|
-
function getOwnInitEvent(target) {
|
|
107
|
-
if (!target?._namespace)
|
|
108
|
-
return [];
|
|
109
|
-
return [
|
|
110
|
-
...target._namespace.__INIT_EVENT__
|
|
111
|
-
];
|
|
112
|
-
}
|
|
113
|
-
__name(getOwnInitEvent, "getOwnInitEvent");
|
|
114
|
-
function getInitEvent(target) {
|
|
115
|
-
let proto = Object.getPrototypeOf(target);
|
|
116
|
-
const set = /* @__PURE__ */ new Set();
|
|
117
|
-
while (proto?._namespace) {
|
|
118
|
-
proto._namespace.__INIT_EVENT__.forEach((item) => set.add(item));
|
|
119
|
-
proto = Object.getPrototypeOf(proto);
|
|
120
|
-
}
|
|
121
|
-
return [
|
|
122
|
-
...set
|
|
123
|
-
];
|
|
99
|
+
function setVar(proto, key) {
|
|
100
|
+
init(proto);
|
|
101
|
+
proto._namespace.__STATE_VAR__.add(key);
|
|
102
|
+
setExposeKey(proto, key);
|
|
124
103
|
}
|
|
125
|
-
__name(
|
|
126
|
-
function
|
|
127
|
-
init(
|
|
128
|
-
|
|
129
|
-
setExposeKey(target, key);
|
|
130
|
-
}
|
|
131
|
-
__name(setModelVar, "setModelVar");
|
|
132
|
-
function setExposeKey(target, key) {
|
|
133
|
-
init(target);
|
|
134
|
-
target._namespace.__EXPOSE_VAR__.add(key);
|
|
104
|
+
__name(setVar, "setVar");
|
|
105
|
+
function setExposeKey(proto, key) {
|
|
106
|
+
init(proto);
|
|
107
|
+
proto._namespace.__EXPOSE_VAR__.add(key);
|
|
135
108
|
}
|
|
136
109
|
__name(setExposeKey, "setExposeKey");
|
|
137
|
-
function setIgnoreKey(
|
|
138
|
-
init(
|
|
139
|
-
|
|
110
|
+
function setIgnoreKey(proto, key) {
|
|
111
|
+
init(proto);
|
|
112
|
+
proto._namespace.__IGNORE_VAR__.add(key);
|
|
140
113
|
}
|
|
141
114
|
__name(setIgnoreKey, "setIgnoreKey");
|
|
142
|
-
function
|
|
143
|
-
|
|
115
|
+
function getOwnModuleState(instance) {
|
|
116
|
+
instance = Object.getPrototypeOf(instance);
|
|
144
117
|
return [
|
|
145
|
-
...
|
|
118
|
+
...instance._namespace.__STATE_VAR__
|
|
146
119
|
];
|
|
147
120
|
}
|
|
148
|
-
__name(
|
|
149
|
-
function
|
|
150
|
-
let proto = Object.getPrototypeOf(
|
|
121
|
+
__name(getOwnModuleState, "getOwnModuleState");
|
|
122
|
+
function getModuleState(instance) {
|
|
123
|
+
let proto = Object.getPrototypeOf(instance);
|
|
151
124
|
const set = /* @__PURE__ */ new Set();
|
|
152
125
|
while (proto?._namespace) {
|
|
153
126
|
proto._namespace.__STATE_VAR__.forEach((item) => set.add(item));
|
|
@@ -157,16 +130,16 @@ function getModelState(target) {
|
|
|
157
130
|
...set
|
|
158
131
|
];
|
|
159
132
|
}
|
|
160
|
-
__name(
|
|
161
|
-
function getOwnExposeKey(
|
|
162
|
-
|
|
133
|
+
__name(getModuleState, "getModuleState");
|
|
134
|
+
function getOwnExposeKey(instance) {
|
|
135
|
+
instance = Object.getPrototypeOf(instance);
|
|
163
136
|
return [
|
|
164
|
-
...
|
|
165
|
-
].filter((item) => !
|
|
137
|
+
...instance._namespace.__EXPOSE_VAR__
|
|
138
|
+
].filter((item) => !instance._namespace.__IGNORE_VAR__.has(item));
|
|
166
139
|
}
|
|
167
140
|
__name(getOwnExposeKey, "getOwnExposeKey");
|
|
168
|
-
function getExposeKey(
|
|
169
|
-
let proto = Object.getPrototypeOf(
|
|
141
|
+
function getExposeKey(instance) {
|
|
142
|
+
let proto = Object.getPrototypeOf(instance);
|
|
170
143
|
const set = /* @__PURE__ */ new Set();
|
|
171
144
|
while (proto?._namespace) {
|
|
172
145
|
[
|
|
@@ -179,32 +152,32 @@ function getExposeKey(target) {
|
|
|
179
152
|
];
|
|
180
153
|
}
|
|
181
154
|
__name(getExposeKey, "getExposeKey");
|
|
182
|
-
function getOwnIgnoreKey(
|
|
183
|
-
if (!
|
|
155
|
+
function getOwnIgnoreKey(instance) {
|
|
156
|
+
if (!instance?._namespace)
|
|
184
157
|
return [];
|
|
185
158
|
return [
|
|
186
|
-
...
|
|
159
|
+
...instance._namespace.__IGNORE_VAR__
|
|
187
160
|
];
|
|
188
161
|
}
|
|
189
162
|
__name(getOwnIgnoreKey, "getOwnIgnoreKey");
|
|
190
|
-
function regisHandler(
|
|
191
|
-
init(
|
|
192
|
-
if (!
|
|
193
|
-
|
|
163
|
+
function regisHandler(proto, key, handler) {
|
|
164
|
+
init(proto);
|
|
165
|
+
if (!proto._namespace.__STATE_HANDLER__.has(key))
|
|
166
|
+
proto._namespace.__STATE_HANDLER__.set(key, [
|
|
194
167
|
handler
|
|
195
168
|
]);
|
|
196
169
|
else
|
|
197
|
-
|
|
170
|
+
proto._namespace.__STATE_HANDLER__.get(key).push(handler);
|
|
198
171
|
}
|
|
199
172
|
__name(regisHandler, "regisHandler");
|
|
200
|
-
function getOwnHandler(
|
|
201
|
-
if (!
|
|
173
|
+
function getOwnHandler(instance, key) {
|
|
174
|
+
if (!instance?._namespace)
|
|
202
175
|
return [];
|
|
203
|
-
return
|
|
176
|
+
return instance._namespace.__STATE_HANDLER__.get(key) || [];
|
|
204
177
|
}
|
|
205
178
|
__name(getOwnHandler, "getOwnHandler");
|
|
206
|
-
function getHandler(
|
|
207
|
-
let proto = Object.getPrototypeOf(
|
|
179
|
+
function getHandler(instance, key) {
|
|
180
|
+
let proto = Object.getPrototypeOf(instance);
|
|
208
181
|
const set = /* @__PURE__ */ new Set();
|
|
209
182
|
while (proto?._namespace) {
|
|
210
183
|
proto._namespace.__STATE_HANDLER__.get(key)?.forEach((item) => set.add(item));
|
|
@@ -215,19 +188,19 @@ function getHandler(target, key) {
|
|
|
215
188
|
];
|
|
216
189
|
}
|
|
217
190
|
__name(getHandler, "getHandler");
|
|
218
|
-
function setState(
|
|
219
|
-
init(
|
|
220
|
-
const namespace =
|
|
191
|
+
function setState(proto, key, state) {
|
|
192
|
+
init(proto);
|
|
193
|
+
const namespace = proto._namespace.__STATE_NAMESPACE__;
|
|
221
194
|
namespace.set(key, state);
|
|
222
195
|
}
|
|
223
196
|
__name(setState, "setState");
|
|
224
|
-
function getOwnState(
|
|
225
|
-
|
|
226
|
-
return
|
|
197
|
+
function getOwnState(instance, key) {
|
|
198
|
+
instance = Object.getPrototypeOf(instance);
|
|
199
|
+
return instance._namespace.__STATE_NAMESPACE__.get(key) || {};
|
|
227
200
|
}
|
|
228
201
|
__name(getOwnState, "getOwnState");
|
|
229
|
-
function getState(
|
|
230
|
-
let proto = Object.getPrototypeOf(
|
|
202
|
+
function getState(instance, key) {
|
|
203
|
+
let proto = Object.getPrototypeOf(instance);
|
|
231
204
|
let ret = {};
|
|
232
205
|
while (proto?._namespace) {
|
|
233
206
|
const state = proto._namespace.__STATE_NAMESPACE__.get(key);
|
|
@@ -241,38 +214,25 @@ function getState(target, key) {
|
|
|
241
214
|
return ret;
|
|
242
215
|
}
|
|
243
216
|
__name(getState, "getState");
|
|
244
|
-
function
|
|
217
|
+
function invokeHandler(event, instance) {
|
|
245
218
|
const stateVars = getExposeKey(instance);
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
219
|
+
const initHandlers = stateVars.map((item) => {
|
|
220
|
+
return getHandler(instance, item).filter((h) => !!h[event]).map((h) => h[event](instance));
|
|
221
|
+
}).flat();
|
|
222
|
+
return Promise.all(initHandlers);
|
|
251
223
|
}
|
|
252
|
-
__name(
|
|
253
|
-
async function registerAsync(instance) {
|
|
254
|
-
const stateVars = getExposeKey(instance);
|
|
255
|
-
for (const item of stateVars) {
|
|
256
|
-
const handlers = getHandler(instance, item);
|
|
257
|
-
for (const hanlder of handlers)
|
|
258
|
-
await hanlder.init?.(instance);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
__name(registerAsync, "registerAsync");
|
|
224
|
+
__name(invokeHandler, "invokeHandler");
|
|
262
225
|
|
|
263
226
|
// src/helper.ts
|
|
264
|
-
function
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
function getBind(Model) {
|
|
274
|
-
const instance = new Model();
|
|
275
|
-
const keys = getModelState(instance);
|
|
227
|
+
function getTag2(moduleOrInstance) {
|
|
228
|
+
if (typeof moduleOrInstance === "object")
|
|
229
|
+
moduleOrInstance = moduleOrInstance.constructor;
|
|
230
|
+
return moduleOrInstance.prototype?.__TAG__ || moduleOrInstance.name;
|
|
231
|
+
}
|
|
232
|
+
__name(getTag2, "getTag");
|
|
233
|
+
function getBind(module2) {
|
|
234
|
+
const instance = new module2();
|
|
235
|
+
const keys = getModuleState(instance);
|
|
276
236
|
const ret = {};
|
|
277
237
|
for (const item of keys) {
|
|
278
238
|
const state = getState(instance, item);
|
|
@@ -282,8 +242,8 @@ function getBind(Model) {
|
|
|
282
242
|
return ret;
|
|
283
243
|
}
|
|
284
244
|
__name(getBind, "getBind");
|
|
285
|
-
function plainToClass(
|
|
286
|
-
const instance = new
|
|
245
|
+
function plainToClass(module2, input) {
|
|
246
|
+
const instance = new module2();
|
|
287
247
|
const keys = getExposeKey(instance);
|
|
288
248
|
for (const item of keys)
|
|
289
249
|
instance[item] = input[item];
|
|
@@ -292,7 +252,7 @@ function plainToClass(Model, input) {
|
|
|
292
252
|
__name(plainToClass, "plainToClass");
|
|
293
253
|
async function transformClass(instance, force = false) {
|
|
294
254
|
const err = [];
|
|
295
|
-
const stateVars =
|
|
255
|
+
const stateVars = getModuleState(instance);
|
|
296
256
|
for (const item of stateVars) {
|
|
297
257
|
const handlers = getHandler(instance, item);
|
|
298
258
|
if (handlers) {
|
|
@@ -336,8 +296,8 @@ function snapShot(data) {
|
|
|
336
296
|
};
|
|
337
297
|
}
|
|
338
298
|
__name(snapShot, "snapShot");
|
|
339
|
-
function addDecoToClass(c, key, handler, type = "
|
|
340
|
-
handler(type === "
|
|
299
|
+
function addDecoToClass(c, key, handler, type = "class") {
|
|
300
|
+
handler(type === "class" ? c.prototype : c, key);
|
|
341
301
|
}
|
|
342
302
|
__name(addDecoToClass, "addDecoToClass");
|
|
343
303
|
function Pipeline(...decos) {
|
|
@@ -349,74 +309,90 @@ function Pipeline(...decos) {
|
|
|
349
309
|
__name(Pipeline, "Pipeline");
|
|
350
310
|
|
|
351
311
|
// src/decorators.ts
|
|
352
|
-
function Init(
|
|
353
|
-
|
|
354
|
-
regisHandler(
|
|
312
|
+
function Init(proto, key) {
|
|
313
|
+
setVar(proto, key);
|
|
314
|
+
regisHandler(proto, key, {
|
|
355
315
|
async init(instance) {
|
|
356
|
-
instance[key]();
|
|
316
|
+
return instance[key]();
|
|
357
317
|
}
|
|
358
318
|
});
|
|
359
319
|
}
|
|
360
320
|
__name(Init, "Init");
|
|
321
|
+
function Unmount(proto, key) {
|
|
322
|
+
setVar(proto, key);
|
|
323
|
+
regisHandler(proto, key, {
|
|
324
|
+
async unmount(instance) {
|
|
325
|
+
return instance[key]();
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
__name(Unmount, "Unmount");
|
|
361
330
|
function Bind(value) {
|
|
362
|
-
return (
|
|
363
|
-
|
|
364
|
-
setState(
|
|
331
|
+
return (proto, k) => {
|
|
332
|
+
setVar(proto, k);
|
|
333
|
+
setState(proto, k, {
|
|
365
334
|
value
|
|
366
335
|
});
|
|
367
336
|
};
|
|
368
337
|
}
|
|
369
338
|
__name(Bind, "Bind");
|
|
370
|
-
function Ignore(
|
|
371
|
-
setIgnoreKey(
|
|
339
|
+
function Ignore(proto, key) {
|
|
340
|
+
setIgnoreKey(proto, key);
|
|
372
341
|
}
|
|
373
342
|
__name(Ignore, "Ignore");
|
|
374
|
-
function Clear(
|
|
375
|
-
init(
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
target._namespace.__STATE_NAMESPACE__.delete(key);
|
|
343
|
+
function Clear(proto, key) {
|
|
344
|
+
init(proto);
|
|
345
|
+
proto._namespace.__EXPOSE_VAR__.delete(key);
|
|
346
|
+
proto._namespace.__IGNORE_VAR__.delete(key);
|
|
347
|
+
proto._namespace.__STATE_VAR__.delete(key);
|
|
348
|
+
proto._namespace.__STATE_HANDLER__.delete(key);
|
|
349
|
+
proto._namespace.__STATE_NAMESPACE__.delete(key);
|
|
382
350
|
}
|
|
383
351
|
__name(Clear, "Clear");
|
|
384
352
|
function Err(cb) {
|
|
385
|
-
return (
|
|
386
|
-
|
|
387
|
-
regisHandler(
|
|
353
|
+
return (proto, key) => {
|
|
354
|
+
setVar(proto, key);
|
|
355
|
+
regisHandler(proto, key, {
|
|
388
356
|
error: cb
|
|
389
357
|
});
|
|
390
358
|
};
|
|
391
359
|
}
|
|
392
360
|
__name(Err, "Err");
|
|
393
|
-
function Expose(
|
|
394
|
-
setExposeKey(
|
|
361
|
+
function Expose(proto, key) {
|
|
362
|
+
setExposeKey(proto, key);
|
|
395
363
|
}
|
|
396
364
|
__name(Expose, "Expose");
|
|
397
|
-
function To(
|
|
398
|
-
return (
|
|
399
|
-
|
|
400
|
-
regisHandler(
|
|
365
|
+
function To(...callbacks) {
|
|
366
|
+
return (proto, key) => {
|
|
367
|
+
setVar(proto, key);
|
|
368
|
+
regisHandler(proto, key, {
|
|
401
369
|
async pipe(instance) {
|
|
402
|
-
|
|
370
|
+
for (const cb of callbacks)
|
|
371
|
+
instance[key] = await cb(instance[key], instance, key);
|
|
403
372
|
}
|
|
404
373
|
});
|
|
405
374
|
};
|
|
406
375
|
}
|
|
407
376
|
__name(To, "To");
|
|
408
377
|
function Tag(tag) {
|
|
409
|
-
return (
|
|
410
|
-
init(
|
|
411
|
-
|
|
378
|
+
return (module2) => {
|
|
379
|
+
init(module2.prototype);
|
|
380
|
+
module2.prototype.__TAG__ = tag;
|
|
412
381
|
};
|
|
413
382
|
}
|
|
414
383
|
__name(Tag, "Tag");
|
|
384
|
+
function Unique(desc) {
|
|
385
|
+
return (module2) => {
|
|
386
|
+
init(module2.prototype);
|
|
387
|
+
module2.prototype.__TAG__ = Symbol(desc || module2.name);
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
__name(Unique, "Unique");
|
|
415
391
|
function Assign(cb) {
|
|
416
|
-
return (
|
|
417
|
-
init(
|
|
418
|
-
|
|
419
|
-
regisHandler(
|
|
392
|
+
return (module2) => {
|
|
393
|
+
init(module2.prototype);
|
|
394
|
+
setVar(module2.prototype, SHARE_KEY);
|
|
395
|
+
regisHandler(module2.prototype, SHARE_KEY, {
|
|
420
396
|
init: async (instance) => {
|
|
421
397
|
const value = await cb(instance);
|
|
422
398
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
@@ -428,10 +404,10 @@ function Assign(cb) {
|
|
|
428
404
|
};
|
|
429
405
|
}
|
|
430
406
|
__name(Assign, "Assign");
|
|
431
|
-
function Global(
|
|
432
|
-
init(
|
|
433
|
-
|
|
434
|
-
regisHandler(
|
|
407
|
+
function Global(module2) {
|
|
408
|
+
init(module2.prototype);
|
|
409
|
+
setVar(module2.prototype, SHARE_KEY);
|
|
410
|
+
regisHandler(module2.prototype, SHARE_KEY, {
|
|
435
411
|
init: async (instance) => {
|
|
436
412
|
const tag = instance.__TAG__;
|
|
437
413
|
if (!tag)
|
|
@@ -443,8 +419,8 @@ function Global(target) {
|
|
|
443
419
|
});
|
|
444
420
|
}
|
|
445
421
|
__name(Global, "Global");
|
|
446
|
-
function Empty(
|
|
447
|
-
init(
|
|
422
|
+
function Empty(module2) {
|
|
423
|
+
init(module2.prototype);
|
|
448
424
|
}
|
|
449
425
|
__name(Empty, "Empty");
|
|
450
426
|
var DataMap = {};
|
|
@@ -461,9 +437,9 @@ function Inject(key) {
|
|
|
461
437
|
return DataMap[key] || EmptyProxy;
|
|
462
438
|
}
|
|
463
439
|
__name(Inject, "Inject");
|
|
464
|
-
function Nested(
|
|
440
|
+
function Nested(module2) {
|
|
465
441
|
return To(async (property) => {
|
|
466
|
-
const instance = plainToClass(
|
|
442
|
+
const instance = plainToClass(module2, property);
|
|
467
443
|
const err = await transformClass(instance);
|
|
468
444
|
if (err.length > 0)
|
|
469
445
|
throw new Error(err[0]);
|
|
@@ -471,8 +447,15 @@ function Nested(Model) {
|
|
|
471
447
|
});
|
|
472
448
|
}
|
|
473
449
|
__name(Nested, "Nested");
|
|
450
|
+
function Isolate() {
|
|
451
|
+
return (target) => {
|
|
452
|
+
init(target.prototype);
|
|
453
|
+
target.prototype.__ISOLATE__ = true;
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
__name(Isolate, "Isolate");
|
|
474
457
|
|
|
475
|
-
// src/
|
|
458
|
+
// src/custom/decorator.ts
|
|
476
459
|
var activeInstance = {};
|
|
477
460
|
function injectProperty(key, value) {
|
|
478
461
|
activeInstance[key] = value;
|
|
@@ -483,28 +466,30 @@ function getProperty(key) {
|
|
|
483
466
|
return activeInstance[key];
|
|
484
467
|
}
|
|
485
468
|
__name(getProperty, "getProperty");
|
|
486
|
-
|
|
487
|
-
// src/custom/decorator.ts
|
|
488
469
|
function Watcher(eventName, options) {
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
470
|
+
let cb;
|
|
471
|
+
return (proto, key) => {
|
|
472
|
+
setVar(proto, key);
|
|
473
|
+
regisHandler(proto, key, {
|
|
492
474
|
init(instance) {
|
|
493
|
-
getProperty("watcher")?.({
|
|
475
|
+
return cb = getProperty("watcher")?.({
|
|
494
476
|
eventName,
|
|
495
477
|
instance,
|
|
496
478
|
key,
|
|
497
479
|
options
|
|
498
480
|
});
|
|
481
|
+
},
|
|
482
|
+
unmount() {
|
|
483
|
+
return cb?.();
|
|
499
484
|
}
|
|
500
485
|
});
|
|
501
486
|
};
|
|
502
487
|
}
|
|
503
488
|
__name(Watcher, "Watcher");
|
|
504
489
|
function Effect(eventName, options) {
|
|
505
|
-
return (
|
|
506
|
-
|
|
507
|
-
regisHandler(
|
|
490
|
+
return (proto, key) => {
|
|
491
|
+
setVar(proto, key);
|
|
492
|
+
regisHandler(proto, key, {
|
|
508
493
|
init(instance) {
|
|
509
494
|
instance[`$_${key}`] = instance[key];
|
|
510
495
|
Object.defineProperty(instance, key, {
|
|
@@ -527,34 +512,40 @@ function Effect(eventName, options) {
|
|
|
527
512
|
};
|
|
528
513
|
}
|
|
529
514
|
__name(Effect, "Effect");
|
|
530
|
-
function Storage(storeKey) {
|
|
531
|
-
|
|
515
|
+
function Storage({ key: storeKey, toJSON, toString } = {}) {
|
|
516
|
+
if (!toJSON)
|
|
517
|
+
toJSON = /* @__PURE__ */ __name((v) => JSON.parse(v), "toJSON");
|
|
518
|
+
if (!toString)
|
|
519
|
+
toString = /* @__PURE__ */ __name((v) => JSON.stringify(v), "toString");
|
|
520
|
+
return (proto, key) => {
|
|
532
521
|
let tag;
|
|
533
522
|
if (key) {
|
|
534
|
-
init(
|
|
535
|
-
tag = storeKey ||
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
regisHandler(target, uniTag, {
|
|
523
|
+
init(proto);
|
|
524
|
+
tag = storeKey || `${getTag(proto)}_${key}`;
|
|
525
|
+
setVar(proto, key);
|
|
526
|
+
regisHandler(proto, key, {
|
|
539
527
|
init: (instance) => {
|
|
540
|
-
getProperty("storage")?.({
|
|
528
|
+
return getProperty("storage")?.({
|
|
541
529
|
instance,
|
|
542
530
|
key,
|
|
543
|
-
tag
|
|
531
|
+
tag,
|
|
532
|
+
toJSON,
|
|
533
|
+
toString
|
|
544
534
|
});
|
|
545
535
|
}
|
|
546
536
|
});
|
|
547
537
|
} else {
|
|
548
|
-
init(
|
|
549
|
-
tag = storeKey ||
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
regisHandler(target.prototype, uniTag, {
|
|
538
|
+
init(proto.prototype);
|
|
539
|
+
tag = storeKey || getTag(proto);
|
|
540
|
+
setVar(proto.prototype, SHARE_KEY);
|
|
541
|
+
regisHandler(proto.prototype, SHARE_KEY, {
|
|
553
542
|
init: (instance) => {
|
|
554
|
-
getProperty("storage")?.({
|
|
543
|
+
return getProperty("storage")?.({
|
|
555
544
|
instance,
|
|
556
|
-
key
|
|
557
|
-
tag
|
|
545
|
+
key,
|
|
546
|
+
tag,
|
|
547
|
+
toJSON,
|
|
548
|
+
toString
|
|
558
549
|
});
|
|
559
550
|
}
|
|
560
551
|
});
|
|
@@ -576,12 +567,16 @@ __name(Storage, "Storage");
|
|
|
576
567
|
Ignore,
|
|
577
568
|
Init,
|
|
578
569
|
Inject,
|
|
570
|
+
Isolate,
|
|
579
571
|
Nested,
|
|
580
572
|
Pipeline,
|
|
581
573
|
Provide,
|
|
574
|
+
SHARE_KEY,
|
|
582
575
|
Storage,
|
|
583
576
|
Tag,
|
|
584
577
|
To,
|
|
578
|
+
Unique,
|
|
579
|
+
Unmount,
|
|
585
580
|
Watcher,
|
|
586
581
|
activeInstance,
|
|
587
582
|
addDecoToClass,
|
|
@@ -589,30 +584,25 @@ __name(Storage, "Storage");
|
|
|
589
584
|
getBind,
|
|
590
585
|
getExposeKey,
|
|
591
586
|
getHandler,
|
|
592
|
-
|
|
593
|
-
getModelState,
|
|
587
|
+
getModuleState,
|
|
594
588
|
getOwnExposeKey,
|
|
595
589
|
getOwnHandler,
|
|
596
590
|
getOwnIgnoreKey,
|
|
597
|
-
|
|
598
|
-
getOwnModelState,
|
|
591
|
+
getOwnModuleState,
|
|
599
592
|
getOwnState,
|
|
600
593
|
getProperty,
|
|
601
594
|
getState,
|
|
602
|
-
getSymbol,
|
|
603
595
|
getTag,
|
|
604
596
|
init,
|
|
605
597
|
injectProperty,
|
|
598
|
+
invokeHandler,
|
|
606
599
|
isPhecda,
|
|
607
600
|
plainToClass,
|
|
608
601
|
regisHandler,
|
|
609
|
-
regisInitEvent,
|
|
610
|
-
register,
|
|
611
|
-
registerAsync,
|
|
612
602
|
setExposeKey,
|
|
613
603
|
setIgnoreKey,
|
|
614
|
-
setModelVar,
|
|
615
604
|
setState,
|
|
605
|
+
setVar,
|
|
616
606
|
snapShot,
|
|
617
607
|
transformClass
|
|
618
608
|
});
|