rename holder to entity

This commit is contained in:
pengfei.zhou 2019-07-17 16:10:26 +08:00
parent 86b048b3b4
commit 44ad1a58c7

View File

@ -77,7 +77,7 @@ export function jsCallReject(contextId: string, callbackId: string, args?: any)
} }
export class Context { export class Context {
holder: any entity: any
id: string id: string
callbacks: Map<string, { resolve: Function, reject: Function }> = new Map callbacks: Map<string, { resolve: Function, reject: Function }> = new Map
constructor(id: string) { constructor(id: string) {
@ -95,7 +95,7 @@ export class Context {
}) })
} }
registor(instance: Object) { registor(instance: Object) {
this.holder = instance this.entity = instance
} }
} }
@ -133,18 +133,22 @@ export function jsRegisterModule(name: string, moduleObject: any) {
gModules.set(name, moduleObject) gModules.set(name, moduleObject)
} }
export function jsCallContextMethod(contextId: string, methodName: string, args?: any) { export function jsCallEntityMethod(contextId: string, methodName: string, args?: any) {
const context = gContexts.get(contextId) const context = gContexts.get(contextId)
if (context === undefined) { if (context === undefined) {
loge(`Cannot find context for context id:${contextId}`) loge(`Cannot find context for context id:${contextId}`)
return return
} }
if (Reflect.has(context, methodName)) { if (context.entity === undefined) {
loge(`Cannot find holder for context id:${contextId}`)
return
}
if (Reflect.has(context.entity, methodName)) {
const argumentsList: any = [] const argumentsList: any = []
for (let i = 2; i < arguments.length; i++) { for (let i = 2; i < arguments.length; i++) {
argumentsList.push(arguments[i]) argumentsList.push(arguments[i])
} }
return Reflect.apply(Reflect.get(context, methodName), context, argumentsList) return Reflect.apply(Reflect.get(context.entity, methodName), context.entity, argumentsList)
} else { } else {
loge(`Cannot find method for context id:${contextId},method name is:${methodName}`) loge(`Cannot find method for context id:${contextId},method name is:${methodName}`)
} }