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

@@ -240,12 +240,11 @@ type ClassType<T> = new (...args: any) => T
export function jsObtainEntry(contextId: string) {
const context = jsObtainContext(contextId)
const exportFunc = (constructor: ClassType<object>) => {
context?.classes?.set(constructor.name, constructor)
const ret = class extends constructor {
context = context
}
context?.register(new ret)
return ret
context?.classes.set(constructor.name, constructor)
const ret = new constructor
Reflect.set(ret, 'context', context)
context?.register(ret)
return constructor
}
return function () {
if (arguments.length === 1) {

View File

@@ -278,19 +278,18 @@ type ClassType<T> = new (...args: any) => T
export function jsObtainEntry(contextId: string) {
const context = jsObtainContext(contextId)
const exportFunc = (constructor: ClassType<object>) => {
context?.classes?.set(constructor.name, constructor)
const ret = class extends constructor {
context = context
}
context?.register(new ret)
return ret
context?.classes.set(constructor.name, constructor)
const ret = new constructor
Reflect.set(ret, 'context', context)
context?.register(ret)
return constructor
}
return function () {
if (arguments.length === 1) {
const args = arguments[0]
if (args instanceof Array) {
args.forEach(clz => {
context?.classes?.set(clz.name, clz)
context?.classes.set(clz.name, clz)
})
return exportFunc
} else {