add responed flow

This commit is contained in:
pengfei.zhou 2019-07-21 06:28:29 +08:00
parent 369a488af6
commit c39629838d
2 changed files with 20 additions and 2 deletions

View File

@ -1,6 +1,7 @@
import { } from './../runtime/global'; import { } from './../runtime/global';
import { View, Stack, Group } from "./view"; import { View, Stack, Group } from "./view";
import { log } from 'util'; import { log } from 'util';
import { loge } from '../util/log';
export function Link(context: any) { export function Link(context: any) {
return <T extends { new(...args: any[]): {} }>(constructor: T) => { return <T extends { new(...args: any[]): {} }>(constructor: T) => {
@ -82,8 +83,25 @@ export abstract class Panel {
} }
@NativeCall @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__() { private __hookBeforeNativeCall__() {

View File

@ -128,7 +128,7 @@ export abstract class View implements Modeling {
isDirty() { isDirty() {
return Reflect.ownKeys(this.__dirty_props__).length === 0 return Reflect.ownKeys(this.__dirty_props__).length === 0
} }
responseCallback(id: string) { responseCallback(id: string, ...args: any) {
const f = this.id2Callback(id) const f = this.id2Callback(id)
if (f instanceof Function) { if (f instanceof Function) {
const argumentsList: any = [] const argumentsList: any = []