This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
2020-10-23 16:04:34 +08:00

36 lines
876 B
JavaScript

import { Panel } from "../ui/panel";
export class ViewHolder {
}
export class ViewModel {
constructor(obj, v) {
this.state = obj;
this.viewHolder = v;
}
getState() {
return this.state;
}
getViewHolder() {
return this.viewHolder;
}
updateState(setter) {
setter(this.state);
this.onBind(this.state, this.viewHolder);
}
attach(view) {
this.viewHolder.build(view);
this.onAttached(this.state, this.viewHolder);
this.onBind(this.state, this.viewHolder);
}
}
export class VMPanel extends Panel {
getViewModel() {
return this.vm;
}
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);
}
}