Add context to ViewModel

This commit is contained in:
pengfei.zhou
2020-09-21 15:58:45 +08:00
committed by osborn
parent 0f9bed3734
commit e0358a3f81
7 changed files with 11 additions and 2 deletions

View File

@@ -1,10 +1,12 @@
import { Group } from "../ui/view";
import { Panel } from "../ui/panel";
import { BridgeContext } from "../runtime/global";
export declare abstract class ViewHolder {
abstract build(root: Group): void;
}
export declare type Setter<M> = (state: M) => void;
export declare abstract class ViewModel<M extends Object, V extends ViewHolder> {
context: BridgeContext;
private state;
private viewHolder;
constructor(obj: M, v: V);

View File

@@ -29,6 +29,7 @@ export class VMPanel extends Panel {
build(root) {
this.vh = new (this.getViewHolderClass());
this.vm = new (this.getViewModelClass())(this.getState(), this.vh);
this.vm.context = this.context;
this.vm.attach(root);
}
}