Add Load Internal Class Support

This commit is contained in:
pengfei.zhou
2020-09-05 11:14:22 +08:00
committed by osborn
parent 6a09c583fc
commit a5ca58c38a
8 changed files with 61 additions and 84 deletions

View File

@@ -23,14 +23,6 @@ export declare function __require__(name: string): any;
export declare function jsRegisterModule(name: string, moduleObject: any): void;
export declare function jsCallEntityMethod(contextId: string, methodName: string, args?: any): any;
declare type ClassType<T> = new (...args: any) => T;
export declare function jsObtainEntry(contextId: string): () => ((constructor: ClassType<object>) => {
new (...args: any): {
context: Context | undefined;
};
}) | {
new (...args: any): {
context: Context | undefined;
};
};
export declare function jsObtainEntry(contextId: string): () => ClassType<object> | ((constructor: ClassType<object>) => ClassType<object>);
export declare function jsCallbackTimer(timerId: number): void;
export {};

View File

@@ -215,24 +215,18 @@ export function jsCallEntityMethod(contextId, methodName, args) {
export function jsObtainEntry(contextId) {
const context = jsObtainContext(contextId);
const exportFunc = (constructor) => {
var _a;
(_a = context === null || context === void 0 ? void 0 : context.classes) === null || _a === void 0 ? void 0 : _a.set(constructor.name, constructor);
const ret = class extends constructor {
constructor() {
super(...arguments);
this.context = context;
}
};
context === null || context === void 0 ? void 0 : context.register(new ret);
return ret;
context === null || context === void 0 ? void 0 : context.classes.set(constructor.name, constructor);
const ret = new constructor;
Reflect.set(ret, 'context', context);
context === null || context === void 0 ? void 0 : context.register(ret);
return constructor;
};
return function () {
if (arguments.length === 1) {
const args = arguments[0];
if (args instanceof Array) {
args.forEach(clz => {
var _a;
(_a = context === null || context === void 0 ? void 0 : context.classes) === null || _a === void 0 ? void 0 : _a.set(clz.name, clz);
context === null || context === void 0 ? void 0 : context.classes.set(clz.name, clz);
});
return exportFunc;
}