phecda-core 3.1.1 → 4.0.0
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 +31 -57
- package/dist/index.d.ts +31 -57
- package/dist/index.js +177 -409
- package/dist/index.mjs +165 -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,61 @@ 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");
|
|
378
191
|
}
|
|
379
|
-
function
|
|
380
|
-
|
|
381
|
-
|
|
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;
|
|
382
238
|
}
|
|
383
239
|
|
|
384
240
|
// src/di.ts
|
|
@@ -414,8 +270,7 @@ function Unique(desc) {
|
|
|
414
270
|
}
|
|
415
271
|
function Assign(cb) {
|
|
416
272
|
return (model) => {
|
|
417
|
-
|
|
418
|
-
setHandler(model, void 0, {
|
|
273
|
+
setMeta(model, void 0, void 0, {
|
|
419
274
|
init: async (instance) => {
|
|
420
275
|
const value = await cb(instance);
|
|
421
276
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
@@ -427,8 +282,7 @@ function Assign(cb) {
|
|
|
427
282
|
};
|
|
428
283
|
}
|
|
429
284
|
function Global(model) {
|
|
430
|
-
|
|
431
|
-
setHandler(model, void 0, {
|
|
285
|
+
setMeta(model, void 0, void 0, {
|
|
432
286
|
init: async (instance) => {
|
|
433
287
|
const tag = getTag(instance);
|
|
434
288
|
if (!globalThis.__PHECDA__)
|
|
@@ -437,68 +291,28 @@ function Global(model) {
|
|
|
437
291
|
}
|
|
438
292
|
});
|
|
439
293
|
}
|
|
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
294
|
function Err(cb, isCatch = false) {
|
|
480
|
-
return (proto,
|
|
481
|
-
|
|
482
|
-
setHandler(proto, key, {
|
|
295
|
+
return (proto, property) => {
|
|
296
|
+
setMeta(proto, property, void 0, {
|
|
483
297
|
init: (instance) => {
|
|
484
|
-
if (typeof instance[
|
|
485
|
-
const oldFn = instance[
|
|
298
|
+
if (typeof instance[property] === "function") {
|
|
299
|
+
const oldFn = instance[property].bind(instance);
|
|
486
300
|
if (isAsyncFunc(oldFn)) {
|
|
487
|
-
instance[
|
|
301
|
+
instance[property] = async (...args) => {
|
|
488
302
|
try {
|
|
489
303
|
await oldFn(...args);
|
|
490
304
|
} catch (e) {
|
|
491
|
-
cb(e, instance,
|
|
305
|
+
cb(e, instance, property);
|
|
492
306
|
if (!isCatch)
|
|
493
307
|
throw e;
|
|
494
308
|
}
|
|
495
309
|
};
|
|
496
310
|
} else {
|
|
497
|
-
instance[
|
|
311
|
+
instance[property] = (...args) => {
|
|
498
312
|
try {
|
|
499
313
|
oldFn(...args);
|
|
500
314
|
} catch (e) {
|
|
501
|
-
cb(e, instance,
|
|
315
|
+
cb(e, instance, property);
|
|
502
316
|
if (!isCatch)
|
|
503
317
|
throw e;
|
|
504
318
|
}
|
|
@@ -511,11 +325,10 @@ function Err(cb, isCatch = false) {
|
|
|
511
325
|
}
|
|
512
326
|
function Watcher(eventName, options) {
|
|
513
327
|
let cb;
|
|
514
|
-
return (proto,
|
|
515
|
-
|
|
516
|
-
setHandler(proto, key, {
|
|
328
|
+
return (proto, property) => {
|
|
329
|
+
setMeta(proto, property, void 0, {
|
|
517
330
|
init(instance) {
|
|
518
|
-
return cb = getInject("watcher")?.({ eventName, instance,
|
|
331
|
+
return cb = getInject("watcher")?.({ eventName, instance, property, options });
|
|
519
332
|
},
|
|
520
333
|
unmount() {
|
|
521
334
|
return cb?.();
|
|
@@ -524,18 +337,17 @@ function Watcher(eventName, options) {
|
|
|
524
337
|
};
|
|
525
338
|
}
|
|
526
339
|
function Effect(cb) {
|
|
527
|
-
return (proto,
|
|
528
|
-
|
|
529
|
-
setHandler(proto, key, {
|
|
340
|
+
return (proto, property) => {
|
|
341
|
+
setMeta(proto, property, void 0, {
|
|
530
342
|
init(instance) {
|
|
531
|
-
instance[`$_${
|
|
532
|
-
Object.defineProperty(instance,
|
|
343
|
+
instance[`$_${property}`] = instance[property];
|
|
344
|
+
Object.defineProperty(instance, property, {
|
|
533
345
|
get() {
|
|
534
|
-
return instance[`$_${
|
|
346
|
+
return instance[`$_${property}`];
|
|
535
347
|
},
|
|
536
348
|
set(v) {
|
|
537
|
-
instance[`$_${
|
|
538
|
-
cb(v, instance,
|
|
349
|
+
instance[`$_${property}`] = v;
|
|
350
|
+
cb(v, instance, property);
|
|
539
351
|
return true;
|
|
540
352
|
}
|
|
541
353
|
});
|
|
@@ -543,31 +355,21 @@ function Effect(cb) {
|
|
|
543
355
|
});
|
|
544
356
|
};
|
|
545
357
|
}
|
|
546
|
-
function Storage({ key
|
|
358
|
+
function Storage({ key, json, stringify } = {}) {
|
|
547
359
|
if (!json)
|
|
548
360
|
json = (v) => JSON.parse(v);
|
|
549
361
|
if (!stringify)
|
|
550
362
|
stringify = (v) => JSON.stringify(v);
|
|
551
|
-
return (proto,
|
|
552
|
-
const tag =
|
|
363
|
+
return (proto, property) => {
|
|
364
|
+
const tag = key || getTag(proto);
|
|
553
365
|
init(proto);
|
|
554
|
-
|
|
555
|
-
setHandler(proto, key, {
|
|
366
|
+
setMeta(proto, property, void 0, {
|
|
556
367
|
init: (instance) => {
|
|
557
|
-
return getInject("storage")?.({ instance,
|
|
368
|
+
return getInject("storage")?.({ instance, property, tag, toJSON: json, toString: stringify });
|
|
558
369
|
}
|
|
559
370
|
});
|
|
560
371
|
};
|
|
561
372
|
}
|
|
562
|
-
function If(value, ...decorators) {
|
|
563
|
-
if (value) {
|
|
564
|
-
return (...args) => {
|
|
565
|
-
decorators.forEach((d) => d(...args));
|
|
566
|
-
};
|
|
567
|
-
}
|
|
568
|
-
return () => {
|
|
569
|
-
};
|
|
570
|
-
}
|
|
571
373
|
|
|
572
374
|
// src/base.ts
|
|
573
375
|
var Base = class {
|
|
@@ -607,7 +409,7 @@ Base = __decorateClass([
|
|
|
607
409
|
export {
|
|
608
410
|
Assign,
|
|
609
411
|
Base,
|
|
610
|
-
|
|
412
|
+
CLEAR_KEY,
|
|
611
413
|
Clear,
|
|
612
414
|
DataMap,
|
|
613
415
|
Effect,
|
|
@@ -616,7 +418,6 @@ export {
|
|
|
616
418
|
Expose,
|
|
617
419
|
Global,
|
|
618
420
|
If,
|
|
619
|
-
Ignore,
|
|
620
421
|
Init,
|
|
621
422
|
Inject,
|
|
622
423
|
Injectable,
|
|
@@ -624,48 +425,32 @@ export {
|
|
|
624
425
|
PHECDA_KEY,
|
|
625
426
|
Pipeline,
|
|
626
427
|
Provide,
|
|
627
|
-
Rule,
|
|
628
428
|
SHARE_KEY,
|
|
629
429
|
Storage,
|
|
630
430
|
Tag,
|
|
631
|
-
To,
|
|
632
431
|
Unique,
|
|
633
432
|
Unmount,
|
|
634
433
|
Watcher,
|
|
635
434
|
activeInstance,
|
|
636
435
|
addDecoToClass,
|
|
637
|
-
classToPlain,
|
|
638
436
|
get,
|
|
639
|
-
getBind,
|
|
640
|
-
getExposeKey,
|
|
641
|
-
getHandler,
|
|
642
437
|
getInject,
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
438
|
+
getMergedMeta,
|
|
439
|
+
getMeta,
|
|
440
|
+
getMetaKey,
|
|
441
|
+
getMetaParams,
|
|
442
|
+
getOwnMeta,
|
|
443
|
+
getOwnMetaKey,
|
|
444
|
+
getOwnMetaParams,
|
|
648
445
|
getPhecdaFromTarget,
|
|
649
|
-
getShareState,
|
|
650
|
-
getState,
|
|
651
|
-
getStateKey,
|
|
652
446
|
getTag,
|
|
653
447
|
init,
|
|
654
|
-
|
|
448
|
+
invoke,
|
|
449
|
+
invokeInit,
|
|
450
|
+
invokeUnmount,
|
|
655
451
|
isAsyncFunc,
|
|
656
452
|
isPhecda,
|
|
657
|
-
plainToClass,
|
|
658
453
|
set,
|
|
659
|
-
setExposeKey,
|
|
660
|
-
setHandler,
|
|
661
|
-
setIgnoreKey,
|
|
662
454
|
setInject,
|
|
663
|
-
|
|
664
|
-
setState,
|
|
665
|
-
setStateKey,
|
|
666
|
-
snapShot,
|
|
667
|
-
transformInstance,
|
|
668
|
-
transformInstanceAsync,
|
|
669
|
-
transformProperty,
|
|
670
|
-
transformPropertyAsync
|
|
455
|
+
setMeta
|
|
671
456
|
};
|