phecda-core 3.0.0-alpha.7 → 3.0.0-alpha.9
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 +6 -7
- package/dist/index.js +7 -28
- package/dist/index.mjs +5 -24
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ interface InjectData {
|
|
|
5
5
|
[key: string]: any;
|
|
6
6
|
}
|
|
7
7
|
type Construct<T = any> = new (...args: any[]) => T;
|
|
8
|
+
type AbConstruct<T = any> = abstract new (...args: any[]) => T;
|
|
8
9
|
interface Handler {
|
|
9
10
|
[key: string]: any;
|
|
10
11
|
}
|
|
@@ -43,8 +44,8 @@ declare function Inject<K extends keyof InjectData>(key: K): InjectData[K];
|
|
|
43
44
|
declare function Nested<M extends new (...args: any) => any>(module: M): (proto: any, key: PropertyKey) => void;
|
|
44
45
|
declare function Isolate(): (target: any) => void;
|
|
45
46
|
|
|
46
|
-
declare function getTag<M extends Construct>(moduleOrInstance: M | InstanceType<M>): PropertyKey;
|
|
47
|
-
declare function getBind<M extends Construct>(module: M): any;
|
|
47
|
+
declare function getTag<M extends Construct | AbConstruct>(moduleOrInstance: M | InstanceType<M>): PropertyKey;
|
|
48
|
+
declare function getBind<M extends Construct | AbConstruct>(module: M): any;
|
|
48
49
|
declare function plainToClass<M extends Construct, Data extends Record<PropertyKey, any>>(module: M, input: Data): InstanceType<M>;
|
|
49
50
|
declare function transformClass<M extends Construct>(instance: InstanceType<M>, force?: boolean): Promise<string[]>;
|
|
50
51
|
declare function classToValue<M>(instance: M): ClassValue<M>;
|
|
@@ -53,7 +54,7 @@ declare function snapShot<T extends Construct>(data: InstanceType<T>): {
|
|
|
53
54
|
clear(): void;
|
|
54
55
|
apply(): void;
|
|
55
56
|
};
|
|
56
|
-
declare function addDecoToClass<M extends Construct>(c: M, key: keyof InstanceType<M> | string, handler: ((target: any, key: PropertyKey) => void), type?: 'property' | 'class'): void;
|
|
57
|
+
declare function addDecoToClass<M extends Construct | AbConstruct>(c: M, key: keyof InstanceType<M> | string, handler: ((target: any, key: PropertyKey) => void), type?: 'property' | 'class'): void;
|
|
57
58
|
declare function Pipeline(...decos: ((...args: any) => void)[]): (...args: any) => void;
|
|
58
59
|
|
|
59
60
|
declare function isPhecda(module: any): module is Construct;
|
|
@@ -73,9 +74,7 @@ declare function getHandler(instance: Phecda, key: PropertyKey): any[];
|
|
|
73
74
|
declare function setState(proto: Phecda, key: PropertyKey, state: Record<string, any>): void;
|
|
74
75
|
declare function getOwnState(instance: Phecda, key: PropertyKey): Object;
|
|
75
76
|
declare function getState(instance: Phecda, key: PropertyKey): any;
|
|
76
|
-
declare function
|
|
77
|
-
declare function registerSerial(instance: Phecda): Promise<void>;
|
|
78
|
-
declare function unmountParallel(instance: Phecda): Promise<any[]>;
|
|
77
|
+
declare function invokeHandler(event: string, instance: Phecda): Promise<any[]>;
|
|
79
78
|
|
|
80
79
|
declare const activeInstance: Record<string, any>;
|
|
81
80
|
declare function injectProperty(key: string, value: any): Record<string, any>;
|
|
@@ -86,4 +85,4 @@ declare function Watcher(eventName: keyof Events, options?: {
|
|
|
86
85
|
declare function Effect(eventName: string, options?: any): (proto: any, key: string) => void;
|
|
87
86
|
declare function Storage(storeKey?: string): (proto: any, key?: PropertyKey) => void;
|
|
88
87
|
|
|
89
|
-
export { Assign, Bind, ClassValue, Clear, Construct, DataMap, Effect, Empty, Err, Events, Expose, Global, Handler, Ignore, Init, Inject, InjectData, Isolate, NameSpace, Nested, Phecda, Pipeline, Provide, SHARE_KEY, Storage, Tag, To, Unique, Unmount, Watcher, activeInstance, addDecoToClass, classToValue, getBind, getExposeKey, getHandler, getModuleState, getOwnExposeKey, getOwnHandler, getOwnIgnoreKey, getOwnModuleState, getOwnState, getProperty, getState, getTag, init, injectProperty, isPhecda, plainToClass, regisHandler,
|
|
88
|
+
export { AbConstruct, Assign, Bind, ClassValue, Clear, Construct, DataMap, Effect, Empty, Err, Events, Expose, Global, Handler, Ignore, Init, Inject, InjectData, Isolate, NameSpace, Nested, Phecda, Pipeline, Provide, SHARE_KEY, Storage, Tag, To, Unique, Unmount, Watcher, activeInstance, addDecoToClass, classToValue, getBind, getExposeKey, getHandler, getModuleState, getOwnExposeKey, getOwnHandler, getOwnIgnoreKey, getOwnModuleState, getOwnState, getProperty, getState, getTag, init, injectProperty, invokeHandler, isPhecda, plainToClass, regisHandler, setExposeKey, setIgnoreKey, setState, setVar, snapShot, transformClass };
|
package/dist/index.js
CHANGED
|
@@ -61,18 +61,16 @@ __export(src_exports, {
|
|
|
61
61
|
getTag: () => getTag,
|
|
62
62
|
init: () => init,
|
|
63
63
|
injectProperty: () => injectProperty,
|
|
64
|
+
invokeHandler: () => invokeHandler,
|
|
64
65
|
isPhecda: () => isPhecda,
|
|
65
66
|
plainToClass: () => plainToClass,
|
|
66
67
|
regisHandler: () => regisHandler,
|
|
67
|
-
registerParallel: () => registerParallel,
|
|
68
|
-
registerSerial: () => registerSerial,
|
|
69
68
|
setExposeKey: () => setExposeKey,
|
|
70
69
|
setIgnoreKey: () => setIgnoreKey,
|
|
71
70
|
setState: () => setState,
|
|
72
71
|
setVar: () => setVar,
|
|
73
72
|
snapShot: () => snapShot,
|
|
74
|
-
transformClass: () => transformClass
|
|
75
|
-
unmountParallel: () => unmountParallel
|
|
73
|
+
transformClass: () => transformClass
|
|
76
74
|
});
|
|
77
75
|
module.exports = __toCommonJS(src_exports);
|
|
78
76
|
|
|
@@ -216,31 +214,14 @@ function getState(instance, key) {
|
|
|
216
214
|
return ret;
|
|
217
215
|
}
|
|
218
216
|
__name(getState, "getState");
|
|
219
|
-
function
|
|
217
|
+
function invokeHandler(event, instance) {
|
|
220
218
|
const stateVars = getExposeKey(instance);
|
|
221
219
|
const initHandlers = stateVars.map((item) => {
|
|
222
|
-
return getHandler(instance, item).filter((h) => h
|
|
220
|
+
return getHandler(instance, item).filter((h) => h[event]).map((h) => h[event](instance));
|
|
223
221
|
}).flat();
|
|
224
222
|
return Promise.all(initHandlers);
|
|
225
223
|
}
|
|
226
|
-
__name(
|
|
227
|
-
async function registerSerial(instance) {
|
|
228
|
-
const stateVars = getExposeKey(instance);
|
|
229
|
-
for (const item of stateVars) {
|
|
230
|
-
const handlers = getHandler(instance, item);
|
|
231
|
-
for (const hanlder of handlers)
|
|
232
|
-
await hanlder.init?.(instance);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
__name(registerSerial, "registerSerial");
|
|
236
|
-
function unmountParallel(instance) {
|
|
237
|
-
const stateVars = getExposeKey(instance);
|
|
238
|
-
const initHandlers = stateVars.map((item) => {
|
|
239
|
-
return getHandler(instance, item).filter((h) => h.unmount).map((h) => h.init(instance));
|
|
240
|
-
}).flat();
|
|
241
|
-
return Promise.all(initHandlers);
|
|
242
|
-
}
|
|
243
|
-
__name(unmountParallel, "unmountParallel");
|
|
224
|
+
__name(invokeHandler, "invokeHandler");
|
|
244
225
|
|
|
245
226
|
// src/helper.ts
|
|
246
227
|
function getTag(moduleOrInstance) {
|
|
@@ -607,16 +588,14 @@ __name(Storage, "Storage");
|
|
|
607
588
|
getTag,
|
|
608
589
|
init,
|
|
609
590
|
injectProperty,
|
|
591
|
+
invokeHandler,
|
|
610
592
|
isPhecda,
|
|
611
593
|
plainToClass,
|
|
612
594
|
regisHandler,
|
|
613
|
-
registerParallel,
|
|
614
|
-
registerSerial,
|
|
615
595
|
setExposeKey,
|
|
616
596
|
setIgnoreKey,
|
|
617
597
|
setState,
|
|
618
598
|
setVar,
|
|
619
599
|
snapShot,
|
|
620
|
-
transformClass
|
|
621
|
-
unmountParallel
|
|
600
|
+
transformClass
|
|
622
601
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -141,31 +141,14 @@ function getState(instance, key) {
|
|
|
141
141
|
return ret;
|
|
142
142
|
}
|
|
143
143
|
__name(getState, "getState");
|
|
144
|
-
function
|
|
144
|
+
function invokeHandler(event, instance) {
|
|
145
145
|
const stateVars = getExposeKey(instance);
|
|
146
146
|
const initHandlers = stateVars.map((item) => {
|
|
147
|
-
return getHandler(instance, item).filter((h) => h
|
|
147
|
+
return getHandler(instance, item).filter((h) => h[event]).map((h) => h[event](instance));
|
|
148
148
|
}).flat();
|
|
149
149
|
return Promise.all(initHandlers);
|
|
150
150
|
}
|
|
151
|
-
__name(
|
|
152
|
-
async function registerSerial(instance) {
|
|
153
|
-
const stateVars = getExposeKey(instance);
|
|
154
|
-
for (const item of stateVars) {
|
|
155
|
-
const handlers = getHandler(instance, item);
|
|
156
|
-
for (const hanlder of handlers)
|
|
157
|
-
await hanlder.init?.(instance);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
__name(registerSerial, "registerSerial");
|
|
161
|
-
function unmountParallel(instance) {
|
|
162
|
-
const stateVars = getExposeKey(instance);
|
|
163
|
-
const initHandlers = stateVars.map((item) => {
|
|
164
|
-
return getHandler(instance, item).filter((h) => h.unmount).map((h) => h.init(instance));
|
|
165
|
-
}).flat();
|
|
166
|
-
return Promise.all(initHandlers);
|
|
167
|
-
}
|
|
168
|
-
__name(unmountParallel, "unmountParallel");
|
|
151
|
+
__name(invokeHandler, "invokeHandler");
|
|
169
152
|
|
|
170
153
|
// src/helper.ts
|
|
171
154
|
function getTag(moduleOrInstance) {
|
|
@@ -531,16 +514,14 @@ export {
|
|
|
531
514
|
getTag,
|
|
532
515
|
init,
|
|
533
516
|
injectProperty,
|
|
517
|
+
invokeHandler,
|
|
534
518
|
isPhecda,
|
|
535
519
|
plainToClass,
|
|
536
520
|
regisHandler,
|
|
537
|
-
registerParallel,
|
|
538
|
-
registerSerial,
|
|
539
521
|
setExposeKey,
|
|
540
522
|
setIgnoreKey,
|
|
541
523
|
setState,
|
|
542
524
|
setVar,
|
|
543
525
|
snapShot,
|
|
544
|
-
transformClass
|
|
545
|
-
unmountParallel
|
|
526
|
+
transformClass
|
|
546
527
|
};
|