Add context to ViewModel
This commit is contained in:
parent
0f9bed3734
commit
e0358a3f81
@ -3476,6 +3476,7 @@ var VMPanel = /** @class */ (function (_super) {
|
||||
VMPanel.prototype.build = function (root) {
|
||||
this.vh = new (this.getViewHolderClass());
|
||||
this.vm = new (this.getViewModelClass())(this.getState(), this.vh);
|
||||
this.vm.context = this.context;
|
||||
this.vm.attach(root);
|
||||
};
|
||||
return VMPanel;
|
||||
|
@ -2695,6 +2695,7 @@ 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);
|
||||
}
|
||||
}
|
||||
|
@ -4184,6 +4184,7 @@ 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);
|
||||
}
|
||||
}
|
||||
|
2
doric-js/index.d.ts
vendored
2
doric-js/index.d.ts
vendored
@ -144,11 +144,13 @@ declare module 'doric/lib/src/ui/panel' {
|
||||
declare module 'doric/lib/src/pattern/mvvm' {
|
||||
import { Group } from "doric/lib/src/ui/view";
|
||||
import { Panel } from "doric/lib/src/ui/panel";
|
||||
import { BridgeContext } from "doric/lib/src/runtime/global";
|
||||
export abstract class ViewHolder {
|
||||
abstract build(root: Group): void;
|
||||
}
|
||||
export type Setter<M> = (state: M) => void;
|
||||
export abstract class ViewModel<M extends Object, V extends ViewHolder> {
|
||||
context: BridgeContext;
|
||||
constructor(obj: M, v: V);
|
||||
getState(): M;
|
||||
getViewHolder(): V;
|
||||
|
2
doric-js/lib/src/pattern/mvvm.d.ts
vendored
2
doric-js/lib/src/pattern/mvvm.d.ts
vendored
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
*/
|
||||
import { Group } from "../ui/view"
|
||||
import { Panel } from "../ui/panel"
|
||||
import { BridgeContext } from "../runtime/global"
|
||||
|
||||
export abstract class ViewHolder {
|
||||
abstract build(root: Group): void
|
||||
@ -23,6 +24,7 @@ export abstract class ViewHolder {
|
||||
export type Setter<M> = (state: M) => void
|
||||
|
||||
export abstract class ViewModel<M extends Object, V extends ViewHolder> {
|
||||
context!: BridgeContext
|
||||
private state: M
|
||||
private viewHolder: V
|
||||
|
||||
@ -57,10 +59,8 @@ export abstract class ViewModel<M extends Object, V extends ViewHolder> {
|
||||
export type ClassType<T> = new (...args: any) => T
|
||||
|
||||
export abstract class VMPanel<M extends Object, V extends ViewHolder> extends Panel {
|
||||
|
||||
private vm?: ViewModel<M, V>
|
||||
private vh?: V
|
||||
|
||||
abstract getViewModelClass(): ClassType<ViewModel<M, V>>
|
||||
|
||||
abstract getState(): M
|
||||
@ -74,6 +74,7 @@ export abstract class VMPanel<M extends Object, V extends ViewHolder> extends Pa
|
||||
build(root: Group): void {
|
||||
this.vh = new (this.getViewHolderClass())
|
||||
this.vm = new (this.getViewModelClass())(this.getState(), this.vh)
|
||||
this.vm.context = this.context
|
||||
this.vm.attach(root)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user