phecda-core 3.1.1 → 4.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/dist/index.d.mts +32 -57
- package/dist/index.d.ts +32 -57
- package/dist/index.js +182 -409
- package/dist/index.mjs +169 -380
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -10,7 +10,8 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
// src/core.ts
|
|
13
|
-
var SHARE_KEY = Symbol("phecda");
|
|
13
|
+
var SHARE_KEY = Symbol("phecda[share]");
|
|
14
|
+
var CLEAR_KEY = Symbol("phecda[clear]");
|
|
14
15
|
var PHECDA_KEY = Symbol("phecda");
|
|
15
16
|
function isPhecda(model) {
|
|
16
17
|
if (typeof model === "function")
|
|
@@ -23,33 +24,9 @@ function init(proto) {
|
|
|
23
24
|
if (!proto.hasOwnProperty(PHECDA_KEY)) {
|
|
24
25
|
proto[PHECDA_KEY] = {
|
|
25
26
|
/**
|
|
26
|
-
*
|
|
27
|
-
* 只要属性上存在至少一个装饰器,该属性就会被捕捉到
|
|
27
|
+
* 元数据
|
|
28
28
|
*/
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @Ignore 绑定的属性,
|
|
32
|
-
* 某属性即使被捕捉,可被强行忽略,优先级最高
|
|
33
|
-
*/
|
|
34
|
-
__IGNORE_KEY: /* @__PURE__ */ new Set(),
|
|
35
|
-
/**
|
|
36
|
-
* @Clear 绑定的属性,
|
|
37
|
-
* 消除父类在该key上的state/handler, 但export key 和 state
|
|
38
|
-
*/
|
|
39
|
-
__CLEAR_KEY: /* @__PURE__ */ new Set(),
|
|
40
|
-
/**
|
|
41
|
-
* 存在状态的变量
|
|
42
|
-
* @deprecated
|
|
43
|
-
*/
|
|
44
|
-
__STATE_KEY: /* @__PURE__ */ new Set(),
|
|
45
|
-
/**
|
|
46
|
-
* 状态变量的处理器
|
|
47
|
-
*/
|
|
48
|
-
__STATE_HANDLER__: /* @__PURE__ */ new Map(),
|
|
49
|
-
/**
|
|
50
|
-
* 状态变量的共有状态
|
|
51
|
-
*/
|
|
52
|
-
__STATE_NAMESPACE__: /* @__PURE__ */ new Map()
|
|
29
|
+
__META__: /* @__PURE__ */ new Map()
|
|
53
30
|
};
|
|
54
31
|
}
|
|
55
32
|
}
|
|
@@ -60,183 +37,127 @@ function getPhecdaFromTarget(target) {
|
|
|
60
37
|
return target;
|
|
61
38
|
return Object.getPrototypeOf(target);
|
|
62
39
|
}
|
|
63
|
-
function
|
|
64
|
-
if (!
|
|
65
|
-
|
|
66
|
-
proto = proto.prototype;
|
|
67
|
-
}
|
|
68
|
-
init(proto);
|
|
69
|
-
proto[PHECDA_KEY].__STATE_KEY.add(key);
|
|
70
|
-
setExposeKey(proto, key);
|
|
71
|
-
}
|
|
72
|
-
function setExposeKey(proto, key) {
|
|
73
|
-
if (!key) {
|
|
74
|
-
key = SHARE_KEY;
|
|
40
|
+
function setMeta(proto, property, index, meta) {
|
|
41
|
+
if (!property) {
|
|
42
|
+
property = SHARE_KEY;
|
|
75
43
|
proto = proto.prototype;
|
|
76
44
|
}
|
|
77
45
|
init(proto);
|
|
78
|
-
proto[PHECDA_KEY].
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
function setHandler(proto, key, handler) {
|
|
89
|
-
if (!key) {
|
|
90
|
-
key = SHARE_KEY;
|
|
91
|
-
proto = proto.prototype;
|
|
92
|
-
}
|
|
93
|
-
init(proto);
|
|
94
|
-
if (!proto[PHECDA_KEY].__STATE_HANDLER__.has(key))
|
|
95
|
-
proto[PHECDA_KEY].__STATE_HANDLER__.set(key, [handler]);
|
|
96
|
-
else
|
|
97
|
-
proto[PHECDA_KEY].__STATE_HANDLER__.get(key).push(handler);
|
|
98
|
-
}
|
|
99
|
-
function setState(proto, key, state) {
|
|
100
|
-
if (!key) {
|
|
101
|
-
key = SHARE_KEY;
|
|
102
|
-
proto = proto.prototype;
|
|
103
|
-
}
|
|
104
|
-
init(proto);
|
|
105
|
-
const namespace = proto[PHECDA_KEY].__STATE_NAMESPACE__;
|
|
106
|
-
namespace.set(key, state);
|
|
107
|
-
}
|
|
108
|
-
function getOwnStateKey(target) {
|
|
109
|
-
const proto = getPhecdaFromTarget(target);
|
|
110
|
-
return [...proto[PHECDA_KEY].__STATE_KEY];
|
|
111
|
-
}
|
|
112
|
-
function getStateKey(target) {
|
|
113
|
-
let proto = getPhecdaFromTarget(target);
|
|
114
|
-
const set2 = /* @__PURE__ */ new Set();
|
|
115
|
-
while (proto?.[PHECDA_KEY]) {
|
|
116
|
-
if (proto.hasOwnProperty(PHECDA_KEY))
|
|
117
|
-
proto[PHECDA_KEY].__STATE_KEY.forEach((item) => set2.add(item));
|
|
118
|
-
proto = Object.getPrototypeOf(proto);
|
|
46
|
+
if (!proto[PHECDA_KEY].__META__.has(property))
|
|
47
|
+
proto[PHECDA_KEY].__META__.set(property, { data: [], params: /* @__PURE__ */ new Map() });
|
|
48
|
+
const oldMeta = proto[PHECDA_KEY].__META__.get(property);
|
|
49
|
+
if (typeof index === "number") {
|
|
50
|
+
if (!oldMeta.params.has(index))
|
|
51
|
+
oldMeta.params.set(index, []);
|
|
52
|
+
const paramsMeta = oldMeta.params.get(index);
|
|
53
|
+
paramsMeta.push(meta);
|
|
54
|
+
} else {
|
|
55
|
+
oldMeta.data.push(meta);
|
|
119
56
|
}
|
|
120
|
-
|
|
57
|
+
proto[PHECDA_KEY].__META__.set(property, oldMeta);
|
|
121
58
|
}
|
|
122
|
-
function
|
|
59
|
+
function getOwnMetaKey(target) {
|
|
123
60
|
const proto = getPhecdaFromTarget(target);
|
|
124
|
-
return [...proto[PHECDA_KEY].
|
|
61
|
+
return [...proto[PHECDA_KEY].__META__.keys()];
|
|
125
62
|
}
|
|
126
|
-
function
|
|
63
|
+
function getMetaKey(target) {
|
|
127
64
|
let proto = getPhecdaFromTarget(target);
|
|
128
65
|
const set2 = /* @__PURE__ */ new Set();
|
|
129
|
-
const origin = proto;
|
|
130
66
|
while (proto?.[PHECDA_KEY]) {
|
|
131
|
-
if (proto.hasOwnProperty(PHECDA_KEY))
|
|
132
|
-
|
|
67
|
+
if (proto.hasOwnProperty(PHECDA_KEY)) {
|
|
68
|
+
for (const property of proto[PHECDA_KEY].__META__.keys())
|
|
69
|
+
set2.add(property);
|
|
70
|
+
}
|
|
133
71
|
proto = Object.getPrototypeOf(proto);
|
|
134
72
|
}
|
|
135
73
|
return [...set2];
|
|
136
74
|
}
|
|
137
|
-
function
|
|
138
|
-
const proto = getPhecdaFromTarget(target);
|
|
139
|
-
return [...proto[PHECDA_KEY]?.__IGNORE_KEY];
|
|
140
|
-
}
|
|
141
|
-
function getOwnHandler(target, key) {
|
|
75
|
+
function getOwnMetaParams(target, key = SHARE_KEY) {
|
|
142
76
|
const proto = getPhecdaFromTarget(target);
|
|
143
|
-
|
|
77
|
+
const { params } = proto[PHECDA_KEY].__META__.get(key);
|
|
78
|
+
return [...params.keys()];
|
|
144
79
|
}
|
|
145
|
-
function
|
|
80
|
+
function getMetaParams(target, key = SHARE_KEY) {
|
|
146
81
|
let proto = getPhecdaFromTarget(target);
|
|
147
82
|
const set2 = /* @__PURE__ */ new Set();
|
|
148
83
|
while (proto?.[PHECDA_KEY]) {
|
|
149
84
|
if (proto.hasOwnProperty(PHECDA_KEY)) {
|
|
150
|
-
proto[PHECDA_KEY].
|
|
151
|
-
if (
|
|
152
|
-
|
|
85
|
+
const meta = proto[PHECDA_KEY].__META__.get(key);
|
|
86
|
+
if (meta) {
|
|
87
|
+
for (const index of meta.params.keys())
|
|
88
|
+
set2.add(index);
|
|
89
|
+
}
|
|
153
90
|
}
|
|
154
91
|
proto = Object.getPrototypeOf(proto);
|
|
155
92
|
}
|
|
156
|
-
return [...set2];
|
|
93
|
+
return [...set2].sort((a, b) => a - b);
|
|
157
94
|
}
|
|
158
|
-
function
|
|
95
|
+
function getMeta(target, property = SHARE_KEY, index) {
|
|
159
96
|
let proto = getPhecdaFromTarget(target);
|
|
160
|
-
|
|
97
|
+
const ret = [];
|
|
161
98
|
while (proto?.[PHECDA_KEY]) {
|
|
162
99
|
if (proto.hasOwnProperty(PHECDA_KEY)) {
|
|
163
|
-
const
|
|
164
|
-
if (
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
100
|
+
const meta = proto[PHECDA_KEY].__META__.get(property);
|
|
101
|
+
if (meta) {
|
|
102
|
+
if (typeof index === "number") {
|
|
103
|
+
const paramMeta = meta.params.get(index);
|
|
104
|
+
if (paramMeta) {
|
|
105
|
+
const index2 = paramMeta.findIndex((item) => item[CLEAR_KEY]);
|
|
106
|
+
ret.unshift(...paramMeta.slice(index2 + 1));
|
|
107
|
+
if (index2 > -1)
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
const index2 = meta.data.findIndex((item) => item[CLEAR_KEY]);
|
|
112
|
+
ret.unshift(...meta.data.slice(index2 + 1));
|
|
113
|
+
if (index2 > -1)
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
168
117
|
}
|
|
169
118
|
proto = Object.getPrototypeOf(proto);
|
|
170
119
|
}
|
|
171
120
|
return ret;
|
|
172
121
|
}
|
|
173
|
-
function
|
|
122
|
+
function getOwnMeta(target, property = SHARE_KEY, index) {
|
|
174
123
|
const proto = getPhecdaFromTarget(target);
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
function invokeHandler(event, module) {
|
|
178
|
-
const stateVars = getExposeKey(module);
|
|
179
|
-
const initHandlers = stateVars.map((item) => {
|
|
180
|
-
return getHandler(module, item).filter((h) => !!h[event]).map((h) => h[event](module));
|
|
181
|
-
}).flat();
|
|
182
|
-
return module.__PROMISE_SYMBOL__ = Promise.all(initHandlers);
|
|
124
|
+
const meta = proto[PHECDA_KEY].__META__.get(property);
|
|
125
|
+
return typeof index === "number" ? meta.params.get(index) : meta.data;
|
|
183
126
|
}
|
|
184
|
-
function set(proto,
|
|
127
|
+
function set(proto, property, value) {
|
|
185
128
|
init(proto);
|
|
186
|
-
proto[`__${
|
|
129
|
+
proto[`__${property.toUpperCase()}__`] = value;
|
|
187
130
|
}
|
|
188
|
-
function get(proto,
|
|
189
|
-
return proto[`__${
|
|
131
|
+
function get(proto, property) {
|
|
132
|
+
return proto[`__${property.toUpperCase()}__`];
|
|
190
133
|
}
|
|
191
134
|
|
|
192
135
|
// src/decorators/core.ts
|
|
193
|
-
function Init(proto,
|
|
194
|
-
|
|
195
|
-
setHandler(proto, key, {
|
|
136
|
+
function Init(proto, property) {
|
|
137
|
+
setMeta(proto, property, void 0, {
|
|
196
138
|
async init(instance) {
|
|
197
|
-
return instance[
|
|
139
|
+
return instance[property]();
|
|
198
140
|
}
|
|
199
141
|
});
|
|
200
142
|
}
|
|
201
|
-
function Unmount(proto,
|
|
202
|
-
|
|
203
|
-
setHandler(proto, key, {
|
|
143
|
+
function Unmount(proto, property) {
|
|
144
|
+
setMeta(proto, property, void 0, {
|
|
204
145
|
async unmount(instance) {
|
|
205
|
-
return instance[
|
|
146
|
+
return instance[property]();
|
|
206
147
|
}
|
|
207
148
|
});
|
|
208
149
|
}
|
|
209
|
-
function
|
|
210
|
-
|
|
211
|
-
setStateKey(proto, k);
|
|
212
|
-
setState(proto, k, {
|
|
213
|
-
value
|
|
214
|
-
});
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
function Ignore(proto, key) {
|
|
218
|
-
if (!key) {
|
|
219
|
-
proto = proto.prototype;
|
|
220
|
-
key = SHARE_KEY;
|
|
221
|
-
}
|
|
222
|
-
;
|
|
223
|
-
setIgnoreKey(proto, key);
|
|
224
|
-
}
|
|
225
|
-
function Clear(proto, key) {
|
|
226
|
-
if (!key) {
|
|
227
|
-
proto = proto.prototype;
|
|
228
|
-
key = SHARE_KEY;
|
|
229
|
-
}
|
|
230
|
-
;
|
|
231
|
-
init(proto);
|
|
232
|
-
proto[PHECDA_KEY].__CLEAR_KEY.add(key);
|
|
233
|
-
}
|
|
234
|
-
function Expose(proto, key) {
|
|
235
|
-
setExposeKey(proto, key);
|
|
150
|
+
function Expose(proto, property, index) {
|
|
151
|
+
setMeta(proto, property, index, {});
|
|
236
152
|
}
|
|
237
153
|
function Empty(model) {
|
|
238
154
|
init(model.prototype);
|
|
239
155
|
}
|
|
156
|
+
function Clear(proto, property, index) {
|
|
157
|
+
setMeta(proto, property, index, {
|
|
158
|
+
[CLEAR_KEY]: true
|
|
159
|
+
});
|
|
160
|
+
}
|
|
240
161
|
function Injectable() {
|
|
241
162
|
return (target) => Empty(target);
|
|
242
163
|
}
|
|
@@ -247,117 +168,6 @@ function getTag(moduleOrInstance) {
|
|
|
247
168
|
moduleOrInstance = moduleOrInstance.constructor;
|
|
248
169
|
return get(moduleOrInstance.prototype, "tag") || moduleOrInstance.name;
|
|
249
170
|
}
|
|
250
|
-
function getBind(model) {
|
|
251
|
-
const instance = new model();
|
|
252
|
-
const keys = getStateKey(instance);
|
|
253
|
-
const ret = {};
|
|
254
|
-
for (const item of keys) {
|
|
255
|
-
const state = getState(instance, item);
|
|
256
|
-
if (state.value)
|
|
257
|
-
ret[item] = state.value;
|
|
258
|
-
}
|
|
259
|
-
return ret;
|
|
260
|
-
}
|
|
261
|
-
function plainToClass(model, input) {
|
|
262
|
-
const instance = new model();
|
|
263
|
-
const keys = getExposeKey(instance);
|
|
264
|
-
for (const item of keys)
|
|
265
|
-
instance[item] = input[item];
|
|
266
|
-
return instance;
|
|
267
|
-
}
|
|
268
|
-
function transformInstance(instance, force = false) {
|
|
269
|
-
const err = [];
|
|
270
|
-
const keys = getExposeKey(instance);
|
|
271
|
-
const addError = err.push.bind(err);
|
|
272
|
-
for (const item of keys) {
|
|
273
|
-
const handlers = getHandler(instance, item);
|
|
274
|
-
if (handlers) {
|
|
275
|
-
for (const handler of handlers) {
|
|
276
|
-
const pipe = handler.pipe;
|
|
277
|
-
if (!pipe)
|
|
278
|
-
continue;
|
|
279
|
-
pipe(instance, addError);
|
|
280
|
-
if (err.length && !force)
|
|
281
|
-
return err;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
return err;
|
|
286
|
-
}
|
|
287
|
-
async function transformInstanceAsync(instance, force = false) {
|
|
288
|
-
const err = [];
|
|
289
|
-
const keys = getExposeKey(instance);
|
|
290
|
-
const addError = err.push.bind(err);
|
|
291
|
-
for (const item of keys) {
|
|
292
|
-
const handlers = getHandler(instance, item);
|
|
293
|
-
if (handlers) {
|
|
294
|
-
for (const handler of handlers) {
|
|
295
|
-
const pipe = handler.pipe;
|
|
296
|
-
if (!pipe)
|
|
297
|
-
continue;
|
|
298
|
-
await pipe(instance, addError);
|
|
299
|
-
if (err.length && !force)
|
|
300
|
-
return err;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
return err;
|
|
305
|
-
}
|
|
306
|
-
function transformProperty(instance, property, force = false) {
|
|
307
|
-
const err = [];
|
|
308
|
-
const handlers = getHandler(instance, property);
|
|
309
|
-
const addError = err.push.bind(err);
|
|
310
|
-
if (handlers) {
|
|
311
|
-
for (const handler of handlers) {
|
|
312
|
-
const pipe = handler.pipe;
|
|
313
|
-
if (!pipe)
|
|
314
|
-
continue;
|
|
315
|
-
pipe(instance, addError);
|
|
316
|
-
if (err.length && !force)
|
|
317
|
-
return err;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
return err;
|
|
321
|
-
}
|
|
322
|
-
async function transformPropertyAsync(instance, property, force = false) {
|
|
323
|
-
const err = [];
|
|
324
|
-
const handlers = getHandler(instance, property);
|
|
325
|
-
const addError = err.push.bind(err);
|
|
326
|
-
if (handlers) {
|
|
327
|
-
for (const handler of handlers) {
|
|
328
|
-
const pipe = handler.pipe;
|
|
329
|
-
if (!pipe)
|
|
330
|
-
continue;
|
|
331
|
-
await pipe(instance, addError);
|
|
332
|
-
if (err.length && !force)
|
|
333
|
-
return err;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
return err;
|
|
337
|
-
}
|
|
338
|
-
function classToPlain(instance) {
|
|
339
|
-
const data = {};
|
|
340
|
-
const exposeVars = getExposeKey(instance);
|
|
341
|
-
for (const item of exposeVars)
|
|
342
|
-
data[item] = instance[item];
|
|
343
|
-
return JSON.parse(JSON.stringify(data));
|
|
344
|
-
}
|
|
345
|
-
function snapShot(data) {
|
|
346
|
-
const snap = {};
|
|
347
|
-
for (const i in data)
|
|
348
|
-
snap[i] = data[i];
|
|
349
|
-
return {
|
|
350
|
-
data,
|
|
351
|
-
clear() {
|
|
352
|
-
for (const i in snap)
|
|
353
|
-
delete data[i];
|
|
354
|
-
},
|
|
355
|
-
apply() {
|
|
356
|
-
for (const i in snap)
|
|
357
|
-
data[i] = snap[i];
|
|
358
|
-
}
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
171
|
function addDecoToClass(c, key, handler) {
|
|
362
172
|
handler(key ? c.prototype : c, key);
|
|
363
173
|
}
|
|
@@ -370,15 +180,64 @@ function Pipeline(...decos) {
|
|
|
370
180
|
function isAsyncFunc(fn) {
|
|
371
181
|
return fn[Symbol.toStringTag] === "AsyncFunction";
|
|
372
182
|
}
|
|
373
|
-
function
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
183
|
+
function invoke(instance, key, ...params) {
|
|
184
|
+
const metaKeys = getMetaKey(instance);
|
|
185
|
+
return Promise.allSettled(metaKeys.map((k) => {
|
|
186
|
+
return getMeta(instance, k);
|
|
187
|
+
}).flat().filter((item) => typeof item[key] === "function").map((item) => item[key](instance, ...params)));
|
|
188
|
+
}
|
|
189
|
+
function invokeInit(instance) {
|
|
190
|
+
return instance.__PROMISE_SYMBOL__ = invoke(instance, "init");
|
|
191
|
+
}
|
|
192
|
+
function invokeUnmount(instance) {
|
|
193
|
+
return instance.__PROMISE_SYMBOL__ = invoke(instance, "unmount");
|
|
194
|
+
}
|
|
195
|
+
function If(value, ...decorators) {
|
|
196
|
+
if (value) {
|
|
197
|
+
return (...args) => {
|
|
198
|
+
decorators.forEach((d) => d(...args));
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
return () => {
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function getMergedMeta(target, property, index, merger = defaultMerger) {
|
|
205
|
+
const meta = getMeta(target, property, index);
|
|
206
|
+
return meta.reduce((p, c) => {
|
|
207
|
+
return merger(p, c);
|
|
208
|
+
}, {});
|
|
209
|
+
}
|
|
210
|
+
function defaultMerger(prev, cur) {
|
|
211
|
+
const newMeta = {};
|
|
212
|
+
for (const key in prev) {
|
|
213
|
+
if (key === CLEAR_KEY)
|
|
214
|
+
continue;
|
|
215
|
+
newMeta[key] = prev[key];
|
|
216
|
+
}
|
|
217
|
+
for (const key in cur) {
|
|
218
|
+
if (key === CLEAR_KEY)
|
|
219
|
+
continue;
|
|
220
|
+
if (newMeta[key] && cur[key]) {
|
|
221
|
+
if (Array.isArray(newMeta[key]) && Array.isArray(cur[key])) {
|
|
222
|
+
const set2 = new Set(newMeta[key]);
|
|
223
|
+
cur[key].forEach((item) => {
|
|
224
|
+
set2.delete(item);
|
|
225
|
+
set2.add(item);
|
|
226
|
+
});
|
|
227
|
+
newMeta[key] = [...set2];
|
|
228
|
+
} else if (typeof newMeta[key] === "object" && typeof cur[key] === "object") {
|
|
229
|
+
newMeta[key] = defaultMerger(newMeta[key], cur[key]);
|
|
230
|
+
} else {
|
|
231
|
+
newMeta[key] = cur[key];
|
|
232
|
+
}
|
|
233
|
+
} else {
|
|
234
|
+
newMeta[key] = cur[key];
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return newMeta;
|
|
378
238
|
}
|
|
379
|
-
function
|
|
380
|
-
|
|
381
|
-
return getter(state);
|
|
239
|
+
function wait(...instances) {
|
|
240
|
+
return Promise.all(instances.map((i) => i.__PROMISE_SYMBOL__));
|
|
382
241
|
}
|
|
383
242
|
|
|
384
243
|
// src/di.ts
|
|
@@ -414,8 +273,7 @@ function Unique(desc) {
|
|
|
414
273
|
}
|
|
415
274
|
function Assign(cb) {
|
|
416
275
|
return (model) => {
|
|
417
|
-
|
|
418
|
-
setHandler(model, void 0, {
|
|
276
|
+
setMeta(model, void 0, void 0, {
|
|
419
277
|
init: async (instance) => {
|
|
420
278
|
const value = await cb(instance);
|
|
421
279
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
@@ -427,8 +285,7 @@ function Assign(cb) {
|
|
|
427
285
|
};
|
|
428
286
|
}
|
|
429
287
|
function Global(model) {
|
|
430
|
-
|
|
431
|
-
setHandler(model, void 0, {
|
|
288
|
+
setMeta(model, void 0, void 0, {
|
|
432
289
|
init: async (instance) => {
|
|
433
290
|
const tag = getTag(instance);
|
|
434
291
|
if (!globalThis.__PHECDA__)
|
|
@@ -437,68 +294,28 @@ function Global(model) {
|
|
|
437
294
|
}
|
|
438
295
|
});
|
|
439
296
|
}
|
|
440
|
-
function To(...callbacks) {
|
|
441
|
-
return (proto, key) => {
|
|
442
|
-
setStateKey(proto, key);
|
|
443
|
-
setHandler(proto, key, {
|
|
444
|
-
async pipe(instance, addError) {
|
|
445
|
-
for (const cb of callbacks) {
|
|
446
|
-
try {
|
|
447
|
-
if (isAsyncFunc(cb))
|
|
448
|
-
instance[key] = await cb(instance[key], instance, key);
|
|
449
|
-
else
|
|
450
|
-
instance[key] = cb(instance[key], instance, key);
|
|
451
|
-
} catch (e) {
|
|
452
|
-
addError(e.message);
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
});
|
|
457
|
-
};
|
|
458
|
-
}
|
|
459
|
-
function Rule(cb, info) {
|
|
460
|
-
return (proto, key) => {
|
|
461
|
-
setStateKey(proto, key);
|
|
462
|
-
setHandler(proto, key, {
|
|
463
|
-
async pipe(instance, addError) {
|
|
464
|
-
let ret;
|
|
465
|
-
if (isAsyncFunc(cb))
|
|
466
|
-
ret = await cb(instance[key]);
|
|
467
|
-
else
|
|
468
|
-
ret = cb(instance[key]);
|
|
469
|
-
if (!ret) {
|
|
470
|
-
if (typeof info === "string")
|
|
471
|
-
addError(info);
|
|
472
|
-
else
|
|
473
|
-
addError(info());
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
});
|
|
477
|
-
};
|
|
478
|
-
}
|
|
479
297
|
function Err(cb, isCatch = false) {
|
|
480
|
-
return (proto,
|
|
481
|
-
|
|
482
|
-
setHandler(proto, key, {
|
|
298
|
+
return (proto, property) => {
|
|
299
|
+
setMeta(proto, property, void 0, {
|
|
483
300
|
init: (instance) => {
|
|
484
|
-
if (typeof instance[
|
|
485
|
-
const oldFn = instance[
|
|
301
|
+
if (typeof instance[property] === "function") {
|
|
302
|
+
const oldFn = instance[property].bind(instance);
|
|
486
303
|
if (isAsyncFunc(oldFn)) {
|
|
487
|
-
instance[
|
|
304
|
+
instance[property] = async (...args) => {
|
|
488
305
|
try {
|
|
489
306
|
await oldFn(...args);
|
|
490
307
|
} catch (e) {
|
|
491
|
-
cb(e, instance,
|
|
308
|
+
cb(e, instance, property);
|
|
492
309
|
if (!isCatch)
|
|
493
310
|
throw e;
|
|
494
311
|
}
|
|
495
312
|
};
|
|
496
313
|
} else {
|
|
497
|
-
instance[
|
|
314
|
+
instance[property] = (...args) => {
|
|
498
315
|
try {
|
|
499
316
|
oldFn(...args);
|
|
500
317
|
} catch (e) {
|
|
501
|
-
cb(e, instance,
|
|
318
|
+
cb(e, instance, property);
|
|
502
319
|
if (!isCatch)
|
|
503
320
|
throw e;
|
|
504
321
|
}
|
|
@@ -511,11 +328,10 @@ function Err(cb, isCatch = false) {
|
|
|
511
328
|
}
|
|
512
329
|
function Watcher(eventName, options) {
|
|
513
330
|
let cb;
|
|
514
|
-
return (proto,
|
|
515
|
-
|
|
516
|
-
setHandler(proto, key, {
|
|
331
|
+
return (proto, property) => {
|
|
332
|
+
setMeta(proto, property, void 0, {
|
|
517
333
|
init(instance) {
|
|
518
|
-
return cb = getInject("watcher")?.({ eventName, instance,
|
|
334
|
+
return cb = getInject("watcher")?.({ eventName, instance, property, options });
|
|
519
335
|
},
|
|
520
336
|
unmount() {
|
|
521
337
|
return cb?.();
|
|
@@ -524,18 +340,17 @@ function Watcher(eventName, options) {
|
|
|
524
340
|
};
|
|
525
341
|
}
|
|
526
342
|
function Effect(cb) {
|
|
527
|
-
return (proto,
|
|
528
|
-
|
|
529
|
-
setHandler(proto, key, {
|
|
343
|
+
return (proto, property) => {
|
|
344
|
+
setMeta(proto, property, void 0, {
|
|
530
345
|
init(instance) {
|
|
531
|
-
instance[`$_${
|
|
532
|
-
Object.defineProperty(instance,
|
|
346
|
+
instance[`$_${property}`] = instance[property];
|
|
347
|
+
Object.defineProperty(instance, property, {
|
|
533
348
|
get() {
|
|
534
|
-
return instance[`$_${
|
|
349
|
+
return instance[`$_${property}`];
|
|
535
350
|
},
|
|
536
351
|
set(v) {
|
|
537
|
-
instance[`$_${
|
|
538
|
-
cb(v, instance,
|
|
352
|
+
instance[`$_${property}`] = v;
|
|
353
|
+
cb(v, instance, property);
|
|
539
354
|
return true;
|
|
540
355
|
}
|
|
541
356
|
});
|
|
@@ -543,31 +358,21 @@ function Effect(cb) {
|
|
|
543
358
|
});
|
|
544
359
|
};
|
|
545
360
|
}
|
|
546
|
-
function Storage({ key
|
|
361
|
+
function Storage({ key, json, stringify } = {}) {
|
|
547
362
|
if (!json)
|
|
548
363
|
json = (v) => JSON.parse(v);
|
|
549
364
|
if (!stringify)
|
|
550
365
|
stringify = (v) => JSON.stringify(v);
|
|
551
|
-
return (proto,
|
|
552
|
-
const tag =
|
|
366
|
+
return (proto, property) => {
|
|
367
|
+
const tag = key || getTag(proto);
|
|
553
368
|
init(proto);
|
|
554
|
-
|
|
555
|
-
setHandler(proto, key, {
|
|
369
|
+
setMeta(proto, property, void 0, {
|
|
556
370
|
init: (instance) => {
|
|
557
|
-
return getInject("storage")?.({ instance,
|
|
371
|
+
return getInject("storage")?.({ instance, property, tag, toJSON: json, toString: stringify });
|
|
558
372
|
}
|
|
559
373
|
});
|
|
560
374
|
};
|
|
561
375
|
}
|
|
562
|
-
function If(value, ...decorators) {
|
|
563
|
-
if (value) {
|
|
564
|
-
return (...args) => {
|
|
565
|
-
decorators.forEach((d) => d(...args));
|
|
566
|
-
};
|
|
567
|
-
}
|
|
568
|
-
return () => {
|
|
569
|
-
};
|
|
570
|
-
}
|
|
571
376
|
|
|
572
377
|
// src/base.ts
|
|
573
378
|
var Base = class {
|
|
@@ -607,7 +412,7 @@ Base = __decorateClass([
|
|
|
607
412
|
export {
|
|
608
413
|
Assign,
|
|
609
414
|
Base,
|
|
610
|
-
|
|
415
|
+
CLEAR_KEY,
|
|
611
416
|
Clear,
|
|
612
417
|
DataMap,
|
|
613
418
|
Effect,
|
|
@@ -616,7 +421,6 @@ export {
|
|
|
616
421
|
Expose,
|
|
617
422
|
Global,
|
|
618
423
|
If,
|
|
619
|
-
Ignore,
|
|
620
424
|
Init,
|
|
621
425
|
Inject,
|
|
622
426
|
Injectable,
|
|
@@ -624,48 +428,33 @@ export {
|
|
|
624
428
|
PHECDA_KEY,
|
|
625
429
|
Pipeline,
|
|
626
430
|
Provide,
|
|
627
|
-
Rule,
|
|
628
431
|
SHARE_KEY,
|
|
629
432
|
Storage,
|
|
630
433
|
Tag,
|
|
631
|
-
To,
|
|
632
434
|
Unique,
|
|
633
435
|
Unmount,
|
|
634
436
|
Watcher,
|
|
635
437
|
activeInstance,
|
|
636
438
|
addDecoToClass,
|
|
637
|
-
classToPlain,
|
|
638
439
|
get,
|
|
639
|
-
getBind,
|
|
640
|
-
getExposeKey,
|
|
641
|
-
getHandler,
|
|
642
440
|
getInject,
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
441
|
+
getMergedMeta,
|
|
442
|
+
getMeta,
|
|
443
|
+
getMetaKey,
|
|
444
|
+
getMetaParams,
|
|
445
|
+
getOwnMeta,
|
|
446
|
+
getOwnMetaKey,
|
|
447
|
+
getOwnMetaParams,
|
|
648
448
|
getPhecdaFromTarget,
|
|
649
|
-
getShareState,
|
|
650
|
-
getState,
|
|
651
|
-
getStateKey,
|
|
652
449
|
getTag,
|
|
653
450
|
init,
|
|
654
|
-
|
|
451
|
+
invoke,
|
|
452
|
+
invokeInit,
|
|
453
|
+
invokeUnmount,
|
|
655
454
|
isAsyncFunc,
|
|
656
455
|
isPhecda,
|
|
657
|
-
plainToClass,
|
|
658
456
|
set,
|
|
659
|
-
setExposeKey,
|
|
660
|
-
setHandler,
|
|
661
|
-
setIgnoreKey,
|
|
662
457
|
setInject,
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
setStateKey,
|
|
666
|
-
snapShot,
|
|
667
|
-
transformInstance,
|
|
668
|
-
transformInstanceAsync,
|
|
669
|
-
transformProperty,
|
|
670
|
-
transformPropertyAsync
|
|
458
|
+
setMeta,
|
|
459
|
+
wait
|
|
671
460
|
};
|