From c39629838d11740a45630c049ec2fb69f88204c1 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Sun, 21 Jul 2019 06:28:29 +0800 Subject: [PATCH] add responed flow --- js-framework/src/ui/panel.ts | 20 +++++++++++++++++++- js-framework/src/ui/view.ts | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/js-framework/src/ui/panel.ts b/js-framework/src/ui/panel.ts index 62561be6..ce6de51e 100644 --- a/js-framework/src/ui/panel.ts +++ b/js-framework/src/ui/panel.ts @@ -1,6 +1,7 @@ import { } from './../runtime/global'; import { View, Stack, Group } from "./view"; import { log } from 'util'; +import { loge } from '../util/log'; export function Link(context: any) { return (constructor: T) => { @@ -82,8 +83,25 @@ export abstract class Panel { } @NativeCall - private __responedCallback__(viewId: string, callbackId: string) { + private __responedCallback__(viewIds: string[], callbackId: string) { + const v = this.retrospectView(viewIds) + if (v === undefined) { + loge(`Cannot find view for ${viewIds}`) + } + const argumentsList: any = [callbackId] + for (let i = 2; i < arguments.length; i++) { + argumentsList.push(arguments[i]) + } + Reflect.apply(v.responseCallback, v, argumentsList) + } + private retrospectView(ids: string[]): View { + return ids.reduce((acc: View, cur) => { + if (acc instanceof Group) { + return acc.children.filter(e => e.viewId === cur)[0] + } + return acc + }, this.__rootView__) } private __hookBeforeNativeCall__() { diff --git a/js-framework/src/ui/view.ts b/js-framework/src/ui/view.ts index 16f78658..1cf17859 100644 --- a/js-framework/src/ui/view.ts +++ b/js-framework/src/ui/view.ts @@ -128,7 +128,7 @@ export abstract class View implements Modeling { isDirty() { return Reflect.ownKeys(this.__dirty_props__).length === 0 } - responseCallback(id: string) { + responseCallback(id: string, ...args: any) { const f = this.id2Callback(id) if (f instanceof Function) { const argumentsList: any = []