phecda-core 3.0.0-alpha.10 → 3.0.0-alpha.11
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 +42 -41
- package/dist/index.js +136 -117
- package/dist/index.mjs +134 -115
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
declare function Init(proto: any, key: PropertyKey): void;
|
|
2
|
+
declare function Unmount(proto: any, key: PropertyKey): void;
|
|
3
|
+
declare function Bind(value: any): (proto: any, k: PropertyKey) => void;
|
|
4
|
+
declare function Ignore(proto: any, key: PropertyKey): void;
|
|
5
|
+
declare function Clear(proto: any, key: PropertyKey): void;
|
|
6
|
+
declare function Expose(proto: any, key: PropertyKey): void;
|
|
7
|
+
declare function Empty(module: any): void;
|
|
8
|
+
|
|
1
9
|
interface NameSpace {
|
|
2
10
|
[name: string]: Phecda;
|
|
3
11
|
}
|
|
@@ -25,37 +33,51 @@ type ClassValue<I> = {
|
|
|
25
33
|
interface Events {
|
|
26
34
|
}
|
|
27
35
|
|
|
28
|
-
declare function
|
|
29
|
-
declare function Unmount(proto: any, key: PropertyKey): void;
|
|
30
|
-
declare function Bind(value: any): (proto: any, k: PropertyKey) => void;
|
|
31
|
-
declare function Ignore(proto: any, key: PropertyKey): void;
|
|
32
|
-
declare function Clear(proto: any, key: PropertyKey): void;
|
|
33
|
-
declare function Err<Fn extends (...args: any) => any>(cb: Fn): (proto: any, key: PropertyKey) => void;
|
|
34
|
-
declare function Expose(proto: any, key: PropertyKey): void;
|
|
35
|
-
declare function To(...callbacks: ((arg: any, instance: any, key: string) => any)[]): (proto: any, key: PropertyKey) => void;
|
|
36
|
+
declare function Isolate(target: any): void;
|
|
36
37
|
declare function Tag(tag: PropertyKey): (module: any) => void;
|
|
37
38
|
declare function Unique(desc?: string): (module: any) => void;
|
|
38
39
|
declare function Assign(cb: (instance?: any) => any): (module: any) => void;
|
|
39
40
|
declare function Global(module: any): void;
|
|
40
|
-
declare function
|
|
41
|
-
declare
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
declare function To(...callbacks: ((arg: any, instance: any, key: string) => any)[]): (proto: any, key: PropertyKey) => void;
|
|
42
|
+
declare function Err(cb: (e: Error | any) => void, isCatch?: boolean): (proto: any, key: PropertyKey) => void;
|
|
43
|
+
interface StorageParam {
|
|
44
|
+
key?: string;
|
|
45
|
+
instance: any;
|
|
46
|
+
tag: string;
|
|
47
|
+
toJSON: (str: string) => any;
|
|
48
|
+
toString: (arg: any) => string;
|
|
49
|
+
}
|
|
50
|
+
interface WatcherParam {
|
|
51
|
+
key: string;
|
|
52
|
+
instance: any;
|
|
53
|
+
eventName: string;
|
|
54
|
+
options?: {
|
|
55
|
+
once?: boolean;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
declare function Watcher(eventName: keyof Events, options?: {
|
|
59
|
+
once?: boolean;
|
|
60
|
+
}): (proto: any, key: string) => void;
|
|
61
|
+
declare function Effect(eventName: string, options?: any): (proto: any, key: string) => void;
|
|
62
|
+
declare function Storage({ key: storeKey, toJSON, toString }?: {
|
|
63
|
+
toJSON?: (str: string) => any;
|
|
64
|
+
toString?: (arg: any) => string;
|
|
65
|
+
key?: string;
|
|
66
|
+
}): (proto: any, key?: PropertyKey) => void;
|
|
46
67
|
|
|
47
68
|
declare function getTag<M extends Construct | AbConstruct>(moduleOrInstance: M | InstanceType<M>): PropertyKey;
|
|
48
69
|
declare function getBind<M extends Construct | AbConstruct>(module: M): any;
|
|
49
70
|
declare function plainToClass<M extends Construct, Data extends Record<PropertyKey, any>>(module: M, input: Data): InstanceType<M>;
|
|
50
71
|
declare function transformClass<M extends Construct>(instance: InstanceType<M>, force?: boolean): Promise<string[]>;
|
|
51
|
-
declare function
|
|
72
|
+
declare function classToPlain<M>(instance: M): ClassValue<M>;
|
|
52
73
|
declare function snapShot<T extends Construct>(data: InstanceType<T>): {
|
|
53
74
|
data: InstanceType<T>;
|
|
54
75
|
clear(): void;
|
|
55
76
|
apply(): void;
|
|
56
77
|
};
|
|
57
|
-
declare function addDecoToClass<M extends Construct | AbConstruct>(c: M, key: keyof InstanceType<M> |
|
|
78
|
+
declare function addDecoToClass<M extends Construct | AbConstruct>(c: M, key: keyof InstanceType<M> | PropertyKey, handler: PropertyDecorator | ClassDecorator): void;
|
|
58
79
|
declare function Pipeline(...decos: ((...args: any) => void)[]): (...args: any) => void;
|
|
80
|
+
declare function isAsyncFunc(fn: Function): boolean;
|
|
59
81
|
|
|
60
82
|
declare function isPhecda(module: any): module is Construct;
|
|
61
83
|
declare const SHARE_KEY: unique symbol;
|
|
@@ -76,32 +98,11 @@ declare function getOwnState(instance: Phecda, key: PropertyKey): Object;
|
|
|
76
98
|
declare function getState(instance: Phecda, key: PropertyKey): any;
|
|
77
99
|
declare function invokeHandler(event: string, instance: Phecda): Promise<any[]>;
|
|
78
100
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
tag: string;
|
|
83
|
-
toJSON: (str: string) => any;
|
|
84
|
-
toString: (arg: any) => string;
|
|
85
|
-
}
|
|
86
|
-
interface WatcherParam {
|
|
87
|
-
key: string;
|
|
88
|
-
instance: any;
|
|
89
|
-
eventName: string;
|
|
90
|
-
options?: {
|
|
91
|
-
once?: boolean;
|
|
92
|
-
};
|
|
93
|
-
}
|
|
101
|
+
declare const DataMap: InjectData;
|
|
102
|
+
declare function Provide<K extends keyof InjectData>(key: K, value: InjectData[K]): void;
|
|
103
|
+
declare function Inject<K extends keyof InjectData>(key: K): InjectData[K];
|
|
94
104
|
declare const activeInstance: Record<string, any>;
|
|
95
105
|
declare function injectProperty(key: string, value: any): Record<string, any>;
|
|
96
106
|
declare function getProperty(key: string): any;
|
|
97
|
-
declare function Watcher(eventName: keyof Events, options?: {
|
|
98
|
-
once?: boolean;
|
|
99
|
-
}): (proto: any, key: string) => void;
|
|
100
|
-
declare function Effect(eventName: string, options?: any): (proto: any, key: string) => void;
|
|
101
|
-
declare function Storage({ key: storeKey, toJSON, toString }?: {
|
|
102
|
-
toJSON?: (str: string) => any;
|
|
103
|
-
toString?: (arg: any) => string;
|
|
104
|
-
key?: string;
|
|
105
|
-
}): (proto: any, key?: PropertyKey) => void;
|
|
106
107
|
|
|
107
|
-
export { AbConstruct, Assign, Bind, ClassValue, Clear, Construct, DataMap, Effect, Empty, Err, Events, Expose, Global, Handler, Ignore, Init, Inject, InjectData, Isolate, NameSpace,
|
|
108
|
+
export { AbConstruct, Assign, Bind, ClassValue, Clear, Construct, DataMap, Effect, Empty, Err, Events, Expose, Global, Handler, Ignore, Init, Inject, InjectData, Isolate, NameSpace, Phecda, Pipeline, Provide, SHARE_KEY, Storage, StorageParam, Tag, To, Unique, Unmount, Watcher, WatcherParam, activeInstance, addDecoToClass, classToPlain, getBind, getExposeKey, getHandler, getModuleState, getOwnExposeKey, getOwnHandler, getOwnIgnoreKey, getOwnModuleState, getOwnState, getProperty, getState, getTag, init, injectProperty, invokeHandler, isAsyncFunc, isPhecda, plainToClass, regisHandler, setExposeKey, setIgnoreKey, setState, setVar, snapShot, transformClass };
|
package/dist/index.js
CHANGED
|
@@ -34,7 +34,6 @@ __export(src_exports, {
|
|
|
34
34
|
Init: () => Init,
|
|
35
35
|
Inject: () => Inject,
|
|
36
36
|
Isolate: () => Isolate,
|
|
37
|
-
Nested: () => Nested,
|
|
38
37
|
Pipeline: () => Pipeline,
|
|
39
38
|
Provide: () => Provide,
|
|
40
39
|
SHARE_KEY: () => SHARE_KEY,
|
|
@@ -46,7 +45,7 @@ __export(src_exports, {
|
|
|
46
45
|
Watcher: () => Watcher,
|
|
47
46
|
activeInstance: () => activeInstance,
|
|
48
47
|
addDecoToClass: () => addDecoToClass,
|
|
49
|
-
|
|
48
|
+
classToPlain: () => classToPlain,
|
|
50
49
|
getBind: () => getBind,
|
|
51
50
|
getExposeKey: () => getExposeKey,
|
|
52
51
|
getHandler: () => getHandler,
|
|
@@ -58,10 +57,11 @@ __export(src_exports, {
|
|
|
58
57
|
getOwnState: () => getOwnState,
|
|
59
58
|
getProperty: () => getProperty,
|
|
60
59
|
getState: () => getState,
|
|
61
|
-
getTag: () =>
|
|
60
|
+
getTag: () => getTag,
|
|
62
61
|
init: () => init,
|
|
63
62
|
injectProperty: () => injectProperty,
|
|
64
63
|
invokeHandler: () => invokeHandler,
|
|
64
|
+
isAsyncFunc: () => isAsyncFunc,
|
|
65
65
|
isPhecda: () => isPhecda,
|
|
66
66
|
plainToClass: () => plainToClass,
|
|
67
67
|
regisHandler: () => regisHandler,
|
|
@@ -223,13 +223,63 @@ function invokeHandler(event, instance) {
|
|
|
223
223
|
}
|
|
224
224
|
__name(invokeHandler, "invokeHandler");
|
|
225
225
|
|
|
226
|
+
// src/decorators/core.ts
|
|
227
|
+
function Init(proto, key) {
|
|
228
|
+
setVar(proto, key);
|
|
229
|
+
regisHandler(proto, key, {
|
|
230
|
+
async init(instance) {
|
|
231
|
+
return instance[key]();
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
__name(Init, "Init");
|
|
236
|
+
function Unmount(proto, key) {
|
|
237
|
+
setVar(proto, key);
|
|
238
|
+
regisHandler(proto, key, {
|
|
239
|
+
async unmount(instance) {
|
|
240
|
+
return instance[key]();
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
__name(Unmount, "Unmount");
|
|
245
|
+
function Bind(value) {
|
|
246
|
+
return (proto, k) => {
|
|
247
|
+
setVar(proto, k);
|
|
248
|
+
setState(proto, k, {
|
|
249
|
+
value
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
__name(Bind, "Bind");
|
|
254
|
+
function Ignore(proto, key) {
|
|
255
|
+
setIgnoreKey(proto, key);
|
|
256
|
+
}
|
|
257
|
+
__name(Ignore, "Ignore");
|
|
258
|
+
function Clear(proto, key) {
|
|
259
|
+
init(proto);
|
|
260
|
+
proto._namespace.__EXPOSE_VAR__.delete(key);
|
|
261
|
+
proto._namespace.__IGNORE_VAR__.delete(key);
|
|
262
|
+
proto._namespace.__STATE_VAR__.delete(key);
|
|
263
|
+
proto._namespace.__STATE_HANDLER__.delete(key);
|
|
264
|
+
proto._namespace.__STATE_NAMESPACE__.delete(key);
|
|
265
|
+
}
|
|
266
|
+
__name(Clear, "Clear");
|
|
267
|
+
function Expose(proto, key) {
|
|
268
|
+
setExposeKey(proto, key);
|
|
269
|
+
}
|
|
270
|
+
__name(Expose, "Expose");
|
|
271
|
+
function Empty(module2) {
|
|
272
|
+
init(module2.prototype);
|
|
273
|
+
}
|
|
274
|
+
__name(Empty, "Empty");
|
|
275
|
+
|
|
226
276
|
// src/helper.ts
|
|
227
|
-
function
|
|
277
|
+
function getTag(moduleOrInstance) {
|
|
228
278
|
if (typeof moduleOrInstance === "object")
|
|
229
279
|
moduleOrInstance = moduleOrInstance.constructor;
|
|
230
280
|
return moduleOrInstance.prototype?.__TAG__ || moduleOrInstance.name;
|
|
231
281
|
}
|
|
232
|
-
__name(
|
|
282
|
+
__name(getTag, "getTag");
|
|
233
283
|
function getBind(module2) {
|
|
234
284
|
const instance = new module2();
|
|
235
285
|
const keys = getModuleState(instance);
|
|
@@ -271,14 +321,14 @@ async function transformClass(instance, force = false) {
|
|
|
271
321
|
return err;
|
|
272
322
|
}
|
|
273
323
|
__name(transformClass, "transformClass");
|
|
274
|
-
function
|
|
324
|
+
function classToPlain(instance) {
|
|
275
325
|
const data = {};
|
|
276
326
|
const exposeVars = getExposeKey(instance);
|
|
277
327
|
for (const item of exposeVars)
|
|
278
328
|
data[item] = instance[item];
|
|
279
|
-
return data;
|
|
329
|
+
return JSON.parse(JSON.stringify(data));
|
|
280
330
|
}
|
|
281
|
-
__name(
|
|
331
|
+
__name(classToPlain, "classToPlain");
|
|
282
332
|
function snapShot(data) {
|
|
283
333
|
const snap = {};
|
|
284
334
|
for (const i in data)
|
|
@@ -296,8 +346,8 @@ function snapShot(data) {
|
|
|
296
346
|
};
|
|
297
347
|
}
|
|
298
348
|
__name(snapShot, "snapShot");
|
|
299
|
-
function addDecoToClass(c, key, handler
|
|
300
|
-
handler(
|
|
349
|
+
function addDecoToClass(c, key, handler) {
|
|
350
|
+
handler(key === SHARE_KEY ? c : c.prototype, key);
|
|
301
351
|
}
|
|
302
352
|
__name(addDecoToClass, "addDecoToClass");
|
|
303
353
|
function Pipeline(...decos) {
|
|
@@ -307,73 +357,43 @@ function Pipeline(...decos) {
|
|
|
307
357
|
};
|
|
308
358
|
}
|
|
309
359
|
__name(Pipeline, "Pipeline");
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
function Init(proto, key) {
|
|
313
|
-
setVar(proto, key);
|
|
314
|
-
regisHandler(proto, key, {
|
|
315
|
-
async init(instance) {
|
|
316
|
-
return instance[key]();
|
|
317
|
-
}
|
|
318
|
-
});
|
|
360
|
+
function isAsyncFunc(fn) {
|
|
361
|
+
return fn[Symbol.toStringTag] === "AsyncFunction";
|
|
319
362
|
}
|
|
320
|
-
__name(
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
__name(Unmount, "Unmount");
|
|
330
|
-
function Bind(value) {
|
|
331
|
-
return (proto, k) => {
|
|
332
|
-
setVar(proto, k);
|
|
333
|
-
setState(proto, k, {
|
|
334
|
-
value
|
|
335
|
-
});
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
__name(Bind, "Bind");
|
|
339
|
-
function Ignore(proto, key) {
|
|
340
|
-
setIgnoreKey(proto, key);
|
|
363
|
+
__name(isAsyncFunc, "isAsyncFunc");
|
|
364
|
+
|
|
365
|
+
// src/di.ts
|
|
366
|
+
var DataMap = {};
|
|
367
|
+
function Provide(key, value) {
|
|
368
|
+
DataMap[key] = value;
|
|
341
369
|
}
|
|
342
|
-
__name(
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
370
|
+
__name(Provide, "Provide");
|
|
371
|
+
var EmptyProxy = new Proxy(Empty, {
|
|
372
|
+
apply() {
|
|
373
|
+
return EmptyProxy;
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
function Inject(key) {
|
|
377
|
+
return DataMap[key] || EmptyProxy;
|
|
350
378
|
}
|
|
351
|
-
__name(
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
error: cb
|
|
357
|
-
});
|
|
358
|
-
};
|
|
379
|
+
__name(Inject, "Inject");
|
|
380
|
+
var activeInstance = {};
|
|
381
|
+
function injectProperty(key, value) {
|
|
382
|
+
activeInstance[key] = value;
|
|
383
|
+
return activeInstance;
|
|
359
384
|
}
|
|
360
|
-
__name(
|
|
361
|
-
function
|
|
362
|
-
|
|
385
|
+
__name(injectProperty, "injectProperty");
|
|
386
|
+
function getProperty(key) {
|
|
387
|
+
return activeInstance[key];
|
|
363
388
|
}
|
|
364
|
-
__name(
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
for (const cb of callbacks)
|
|
371
|
-
instance[key] = await cb(instance[key], instance, key);
|
|
372
|
-
}
|
|
373
|
-
});
|
|
374
|
-
};
|
|
389
|
+
__name(getProperty, "getProperty");
|
|
390
|
+
|
|
391
|
+
// src/decorators/function.ts
|
|
392
|
+
function Isolate(target) {
|
|
393
|
+
init(target.prototype);
|
|
394
|
+
target.prototype.__ISOLATE__ = true;
|
|
375
395
|
}
|
|
376
|
-
__name(
|
|
396
|
+
__name(Isolate, "Isolate");
|
|
377
397
|
function Tag(tag) {
|
|
378
398
|
return (module2) => {
|
|
379
399
|
init(module2.prototype);
|
|
@@ -419,53 +439,52 @@ function Global(module2) {
|
|
|
419
439
|
});
|
|
420
440
|
}
|
|
421
441
|
__name(Global, "Global");
|
|
422
|
-
function
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
var EmptyProxy = new Proxy(Empty, {
|
|
432
|
-
apply() {
|
|
433
|
-
return EmptyProxy;
|
|
434
|
-
}
|
|
435
|
-
});
|
|
436
|
-
function Inject(key) {
|
|
437
|
-
return DataMap[key] || EmptyProxy;
|
|
438
|
-
}
|
|
439
|
-
__name(Inject, "Inject");
|
|
440
|
-
function Nested(module2) {
|
|
441
|
-
return To(async (property) => {
|
|
442
|
-
const instance = plainToClass(module2, property);
|
|
443
|
-
const err = await transformClass(instance);
|
|
444
|
-
if (err.length > 0)
|
|
445
|
-
throw new Error(err[0]);
|
|
446
|
-
return instance;
|
|
447
|
-
});
|
|
448
|
-
}
|
|
449
|
-
__name(Nested, "Nested");
|
|
450
|
-
function Isolate() {
|
|
451
|
-
return (target) => {
|
|
452
|
-
init(target.prototype);
|
|
453
|
-
target.prototype.__ISOLATE__ = true;
|
|
442
|
+
function To(...callbacks) {
|
|
443
|
+
return (proto, key) => {
|
|
444
|
+
setVar(proto, key);
|
|
445
|
+
regisHandler(proto, key, {
|
|
446
|
+
async pipe(instance) {
|
|
447
|
+
for (const cb of callbacks)
|
|
448
|
+
instance[key] = await cb(instance[key], instance, key);
|
|
449
|
+
}
|
|
450
|
+
});
|
|
454
451
|
};
|
|
455
452
|
}
|
|
456
|
-
__name(
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
453
|
+
__name(To, "To");
|
|
454
|
+
function Err(cb, isCatch = false) {
|
|
455
|
+
return (proto, key) => {
|
|
456
|
+
setVar(proto, key);
|
|
457
|
+
regisHandler(proto, key, {
|
|
458
|
+
init: (instance) => {
|
|
459
|
+
if (typeof instance[key] === "function") {
|
|
460
|
+
const oldFn = instance[key].bind(instance);
|
|
461
|
+
if (isAsyncFunc(oldFn)) {
|
|
462
|
+
instance[key] = async (...args) => {
|
|
463
|
+
try {
|
|
464
|
+
await oldFn(...args);
|
|
465
|
+
} catch (e) {
|
|
466
|
+
cb(e);
|
|
467
|
+
if (!isCatch)
|
|
468
|
+
throw e;
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
} else {
|
|
472
|
+
instance[key] = (...args) => {
|
|
473
|
+
try {
|
|
474
|
+
oldFn(...args);
|
|
475
|
+
} catch (e) {
|
|
476
|
+
cb(e);
|
|
477
|
+
if (!isCatch)
|
|
478
|
+
throw e;
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
};
|
|
467
486
|
}
|
|
468
|
-
__name(
|
|
487
|
+
__name(Err, "Err");
|
|
469
488
|
function Watcher(eventName, options) {
|
|
470
489
|
let cb;
|
|
471
490
|
return (proto, key) => {
|
|
@@ -568,7 +587,6 @@ __name(Storage, "Storage");
|
|
|
568
587
|
Init,
|
|
569
588
|
Inject,
|
|
570
589
|
Isolate,
|
|
571
|
-
Nested,
|
|
572
590
|
Pipeline,
|
|
573
591
|
Provide,
|
|
574
592
|
SHARE_KEY,
|
|
@@ -580,7 +598,7 @@ __name(Storage, "Storage");
|
|
|
580
598
|
Watcher,
|
|
581
599
|
activeInstance,
|
|
582
600
|
addDecoToClass,
|
|
583
|
-
|
|
601
|
+
classToPlain,
|
|
584
602
|
getBind,
|
|
585
603
|
getExposeKey,
|
|
586
604
|
getHandler,
|
|
@@ -596,6 +614,7 @@ __name(Storage, "Storage");
|
|
|
596
614
|
init,
|
|
597
615
|
injectProperty,
|
|
598
616
|
invokeHandler,
|
|
617
|
+
isAsyncFunc,
|
|
599
618
|
isPhecda,
|
|
600
619
|
plainToClass,
|
|
601
620
|
regisHandler,
|
package/dist/index.mjs
CHANGED
|
@@ -150,13 +150,63 @@ function invokeHandler(event, instance) {
|
|
|
150
150
|
}
|
|
151
151
|
__name(invokeHandler, "invokeHandler");
|
|
152
152
|
|
|
153
|
+
// src/decorators/core.ts
|
|
154
|
+
function Init(proto, key) {
|
|
155
|
+
setVar(proto, key);
|
|
156
|
+
regisHandler(proto, key, {
|
|
157
|
+
async init(instance) {
|
|
158
|
+
return instance[key]();
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
__name(Init, "Init");
|
|
163
|
+
function Unmount(proto, key) {
|
|
164
|
+
setVar(proto, key);
|
|
165
|
+
regisHandler(proto, key, {
|
|
166
|
+
async unmount(instance) {
|
|
167
|
+
return instance[key]();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
__name(Unmount, "Unmount");
|
|
172
|
+
function Bind(value) {
|
|
173
|
+
return (proto, k) => {
|
|
174
|
+
setVar(proto, k);
|
|
175
|
+
setState(proto, k, {
|
|
176
|
+
value
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
__name(Bind, "Bind");
|
|
181
|
+
function Ignore(proto, key) {
|
|
182
|
+
setIgnoreKey(proto, key);
|
|
183
|
+
}
|
|
184
|
+
__name(Ignore, "Ignore");
|
|
185
|
+
function Clear(proto, key) {
|
|
186
|
+
init(proto);
|
|
187
|
+
proto._namespace.__EXPOSE_VAR__.delete(key);
|
|
188
|
+
proto._namespace.__IGNORE_VAR__.delete(key);
|
|
189
|
+
proto._namespace.__STATE_VAR__.delete(key);
|
|
190
|
+
proto._namespace.__STATE_HANDLER__.delete(key);
|
|
191
|
+
proto._namespace.__STATE_NAMESPACE__.delete(key);
|
|
192
|
+
}
|
|
193
|
+
__name(Clear, "Clear");
|
|
194
|
+
function Expose(proto, key) {
|
|
195
|
+
setExposeKey(proto, key);
|
|
196
|
+
}
|
|
197
|
+
__name(Expose, "Expose");
|
|
198
|
+
function Empty(module) {
|
|
199
|
+
init(module.prototype);
|
|
200
|
+
}
|
|
201
|
+
__name(Empty, "Empty");
|
|
202
|
+
|
|
153
203
|
// src/helper.ts
|
|
154
|
-
function
|
|
204
|
+
function getTag(moduleOrInstance) {
|
|
155
205
|
if (typeof moduleOrInstance === "object")
|
|
156
206
|
moduleOrInstance = moduleOrInstance.constructor;
|
|
157
207
|
return moduleOrInstance.prototype?.__TAG__ || moduleOrInstance.name;
|
|
158
208
|
}
|
|
159
|
-
__name(
|
|
209
|
+
__name(getTag, "getTag");
|
|
160
210
|
function getBind(module) {
|
|
161
211
|
const instance = new module();
|
|
162
212
|
const keys = getModuleState(instance);
|
|
@@ -198,14 +248,14 @@ async function transformClass(instance, force = false) {
|
|
|
198
248
|
return err;
|
|
199
249
|
}
|
|
200
250
|
__name(transformClass, "transformClass");
|
|
201
|
-
function
|
|
251
|
+
function classToPlain(instance) {
|
|
202
252
|
const data = {};
|
|
203
253
|
const exposeVars = getExposeKey(instance);
|
|
204
254
|
for (const item of exposeVars)
|
|
205
255
|
data[item] = instance[item];
|
|
206
|
-
return data;
|
|
256
|
+
return JSON.parse(JSON.stringify(data));
|
|
207
257
|
}
|
|
208
|
-
__name(
|
|
258
|
+
__name(classToPlain, "classToPlain");
|
|
209
259
|
function snapShot(data) {
|
|
210
260
|
const snap = {};
|
|
211
261
|
for (const i in data)
|
|
@@ -223,8 +273,8 @@ function snapShot(data) {
|
|
|
223
273
|
};
|
|
224
274
|
}
|
|
225
275
|
__name(snapShot, "snapShot");
|
|
226
|
-
function addDecoToClass(c, key, handler
|
|
227
|
-
handler(
|
|
276
|
+
function addDecoToClass(c, key, handler) {
|
|
277
|
+
handler(key === SHARE_KEY ? c : c.prototype, key);
|
|
228
278
|
}
|
|
229
279
|
__name(addDecoToClass, "addDecoToClass");
|
|
230
280
|
function Pipeline(...decos) {
|
|
@@ -234,73 +284,43 @@ function Pipeline(...decos) {
|
|
|
234
284
|
};
|
|
235
285
|
}
|
|
236
286
|
__name(Pipeline, "Pipeline");
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
function Init(proto, key) {
|
|
240
|
-
setVar(proto, key);
|
|
241
|
-
regisHandler(proto, key, {
|
|
242
|
-
async init(instance) {
|
|
243
|
-
return instance[key]();
|
|
244
|
-
}
|
|
245
|
-
});
|
|
287
|
+
function isAsyncFunc(fn) {
|
|
288
|
+
return fn[Symbol.toStringTag] === "AsyncFunction";
|
|
246
289
|
}
|
|
247
|
-
__name(
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
__name(Unmount, "Unmount");
|
|
257
|
-
function Bind(value) {
|
|
258
|
-
return (proto, k) => {
|
|
259
|
-
setVar(proto, k);
|
|
260
|
-
setState(proto, k, {
|
|
261
|
-
value
|
|
262
|
-
});
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
__name(Bind, "Bind");
|
|
266
|
-
function Ignore(proto, key) {
|
|
267
|
-
setIgnoreKey(proto, key);
|
|
290
|
+
__name(isAsyncFunc, "isAsyncFunc");
|
|
291
|
+
|
|
292
|
+
// src/di.ts
|
|
293
|
+
var DataMap = {};
|
|
294
|
+
function Provide(key, value) {
|
|
295
|
+
DataMap[key] = value;
|
|
268
296
|
}
|
|
269
|
-
__name(
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
297
|
+
__name(Provide, "Provide");
|
|
298
|
+
var EmptyProxy = new Proxy(Empty, {
|
|
299
|
+
apply() {
|
|
300
|
+
return EmptyProxy;
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
function Inject(key) {
|
|
304
|
+
return DataMap[key] || EmptyProxy;
|
|
277
305
|
}
|
|
278
|
-
__name(
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
error: cb
|
|
284
|
-
});
|
|
285
|
-
};
|
|
306
|
+
__name(Inject, "Inject");
|
|
307
|
+
var activeInstance = {};
|
|
308
|
+
function injectProperty(key, value) {
|
|
309
|
+
activeInstance[key] = value;
|
|
310
|
+
return activeInstance;
|
|
286
311
|
}
|
|
287
|
-
__name(
|
|
288
|
-
function
|
|
289
|
-
|
|
312
|
+
__name(injectProperty, "injectProperty");
|
|
313
|
+
function getProperty(key) {
|
|
314
|
+
return activeInstance[key];
|
|
290
315
|
}
|
|
291
|
-
__name(
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
for (const cb of callbacks)
|
|
298
|
-
instance[key] = await cb(instance[key], instance, key);
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
};
|
|
316
|
+
__name(getProperty, "getProperty");
|
|
317
|
+
|
|
318
|
+
// src/decorators/function.ts
|
|
319
|
+
function Isolate(target) {
|
|
320
|
+
init(target.prototype);
|
|
321
|
+
target.prototype.__ISOLATE__ = true;
|
|
302
322
|
}
|
|
303
|
-
__name(
|
|
323
|
+
__name(Isolate, "Isolate");
|
|
304
324
|
function Tag(tag) {
|
|
305
325
|
return (module) => {
|
|
306
326
|
init(module.prototype);
|
|
@@ -346,53 +366,52 @@ function Global(module) {
|
|
|
346
366
|
});
|
|
347
367
|
}
|
|
348
368
|
__name(Global, "Global");
|
|
349
|
-
function
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
var EmptyProxy = new Proxy(Empty, {
|
|
359
|
-
apply() {
|
|
360
|
-
return EmptyProxy;
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
function Inject(key) {
|
|
364
|
-
return DataMap[key] || EmptyProxy;
|
|
365
|
-
}
|
|
366
|
-
__name(Inject, "Inject");
|
|
367
|
-
function Nested(module) {
|
|
368
|
-
return To(async (property) => {
|
|
369
|
-
const instance = plainToClass(module, property);
|
|
370
|
-
const err = await transformClass(instance);
|
|
371
|
-
if (err.length > 0)
|
|
372
|
-
throw new Error(err[0]);
|
|
373
|
-
return instance;
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
__name(Nested, "Nested");
|
|
377
|
-
function Isolate() {
|
|
378
|
-
return (target) => {
|
|
379
|
-
init(target.prototype);
|
|
380
|
-
target.prototype.__ISOLATE__ = true;
|
|
369
|
+
function To(...callbacks) {
|
|
370
|
+
return (proto, key) => {
|
|
371
|
+
setVar(proto, key);
|
|
372
|
+
regisHandler(proto, key, {
|
|
373
|
+
async pipe(instance) {
|
|
374
|
+
for (const cb of callbacks)
|
|
375
|
+
instance[key] = await cb(instance[key], instance, key);
|
|
376
|
+
}
|
|
377
|
+
});
|
|
381
378
|
};
|
|
382
379
|
}
|
|
383
|
-
__name(
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
380
|
+
__name(To, "To");
|
|
381
|
+
function Err(cb, isCatch = false) {
|
|
382
|
+
return (proto, key) => {
|
|
383
|
+
setVar(proto, key);
|
|
384
|
+
regisHandler(proto, key, {
|
|
385
|
+
init: (instance) => {
|
|
386
|
+
if (typeof instance[key] === "function") {
|
|
387
|
+
const oldFn = instance[key].bind(instance);
|
|
388
|
+
if (isAsyncFunc(oldFn)) {
|
|
389
|
+
instance[key] = async (...args) => {
|
|
390
|
+
try {
|
|
391
|
+
await oldFn(...args);
|
|
392
|
+
} catch (e) {
|
|
393
|
+
cb(e);
|
|
394
|
+
if (!isCatch)
|
|
395
|
+
throw e;
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
} else {
|
|
399
|
+
instance[key] = (...args) => {
|
|
400
|
+
try {
|
|
401
|
+
oldFn(...args);
|
|
402
|
+
} catch (e) {
|
|
403
|
+
cb(e);
|
|
404
|
+
if (!isCatch)
|
|
405
|
+
throw e;
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
};
|
|
394
413
|
}
|
|
395
|
-
__name(
|
|
414
|
+
__name(Err, "Err");
|
|
396
415
|
function Watcher(eventName, options) {
|
|
397
416
|
let cb;
|
|
398
417
|
return (proto, key) => {
|
|
@@ -494,7 +513,6 @@ export {
|
|
|
494
513
|
Init,
|
|
495
514
|
Inject,
|
|
496
515
|
Isolate,
|
|
497
|
-
Nested,
|
|
498
516
|
Pipeline,
|
|
499
517
|
Provide,
|
|
500
518
|
SHARE_KEY,
|
|
@@ -506,7 +524,7 @@ export {
|
|
|
506
524
|
Watcher,
|
|
507
525
|
activeInstance,
|
|
508
526
|
addDecoToClass,
|
|
509
|
-
|
|
527
|
+
classToPlain,
|
|
510
528
|
getBind,
|
|
511
529
|
getExposeKey,
|
|
512
530
|
getHandler,
|
|
@@ -518,10 +536,11 @@ export {
|
|
|
518
536
|
getOwnState,
|
|
519
537
|
getProperty,
|
|
520
538
|
getState,
|
|
521
|
-
|
|
539
|
+
getTag,
|
|
522
540
|
init,
|
|
523
541
|
injectProperty,
|
|
524
542
|
invokeHandler,
|
|
543
|
+
isAsyncFunc,
|
|
525
544
|
isPhecda,
|
|
526
545
|
plainToClass,
|
|
527
546
|
regisHandler,
|