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) {
|
VMPanel.prototype.build = function (root) {
|
||||||
this.vh = new (this.getViewHolderClass());
|
this.vh = new (this.getViewHolderClass());
|
||||||
this.vm = new (this.getViewModelClass())(this.getState(), this.vh);
|
this.vm = new (this.getViewModelClass())(this.getState(), this.vh);
|
||||||
|
this.vm.context = this.context;
|
||||||
this.vm.attach(root);
|
this.vm.attach(root);
|
||||||
};
|
};
|
||||||
return VMPanel;
|
return VMPanel;
|
||||||
|
@ -2695,6 +2695,7 @@ class VMPanel extends Panel {
|
|||||||
build(root) {
|
build(root) {
|
||||||
this.vh = new (this.getViewHolderClass());
|
this.vh = new (this.getViewHolderClass());
|
||||||
this.vm = new (this.getViewModelClass())(this.getState(), this.vh);
|
this.vm = new (this.getViewModelClass())(this.getState(), this.vh);
|
||||||
|
this.vm.context = this.context;
|
||||||
this.vm.attach(root);
|
this.vm.attach(root);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4184,6 +4184,7 @@ class VMPanel extends Panel {
|
|||||||
build(root) {
|
build(root) {
|
||||||
this.vh = new (this.getViewHolderClass());
|
this.vh = new (this.getViewHolderClass());
|
||||||
this.vm = new (this.getViewModelClass())(this.getState(), this.vh);
|
this.vm = new (this.getViewModelClass())(this.getState(), this.vh);
|
||||||
|
this.vm.context = this.context;
|
||||||
this.vm.attach(root);
|
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' {
|
declare module 'doric/lib/src/pattern/mvvm' {
|
||||||
import { Group } from "doric/lib/src/ui/view";
|
import { Group } from "doric/lib/src/ui/view";
|
||||||
import { Panel } from "doric/lib/src/ui/panel";
|
import { Panel } from "doric/lib/src/ui/panel";
|
||||||
|
import { BridgeContext } from "doric/lib/src/runtime/global";
|
||||||
export abstract class ViewHolder {
|
export abstract class ViewHolder {
|
||||||
abstract build(root: Group): void;
|
abstract build(root: Group): void;
|
||||||
}
|
}
|
||||||
export type Setter<M> = (state: M) => void;
|
export type Setter<M> = (state: M) => void;
|
||||||
export abstract class ViewModel<M extends Object, V extends ViewHolder> {
|
export abstract class ViewModel<M extends Object, V extends ViewHolder> {
|
||||||
|
context: BridgeContext;
|
||||||
constructor(obj: M, v: V);
|
constructor(obj: M, v: V);
|
||||||
getState(): M;
|
getState(): M;
|
||||||
getViewHolder(): V;
|
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 { Group } from "../ui/view";
|
||||||
import { Panel } from "../ui/panel";
|
import { Panel } from "../ui/panel";
|
||||||
|
import { BridgeContext } from "../runtime/global";
|
||||||
export declare abstract class ViewHolder {
|
export declare abstract class ViewHolder {
|
||||||
abstract build(root: Group): void;
|
abstract build(root: Group): void;
|
||||||
}
|
}
|
||||||
export declare type Setter<M> = (state: M) => void;
|
export declare type Setter<M> = (state: M) => void;
|
||||||
export declare abstract class ViewModel<M extends Object, V extends ViewHolder> {
|
export declare abstract class ViewModel<M extends Object, V extends ViewHolder> {
|
||||||
|
context: BridgeContext;
|
||||||
private state;
|
private state;
|
||||||
private viewHolder;
|
private viewHolder;
|
||||||
constructor(obj: M, v: V);
|
constructor(obj: M, v: V);
|
||||||
|
@ -29,6 +29,7 @@ export class VMPanel extends Panel {
|
|||||||
build(root) {
|
build(root) {
|
||||||
this.vh = new (this.getViewHolderClass());
|
this.vh = new (this.getViewHolderClass());
|
||||||
this.vm = new (this.getViewModelClass())(this.getState(), this.vh);
|
this.vm = new (this.getViewModelClass())(this.getState(), this.vh);
|
||||||
|
this.vm.context = this.context;
|
||||||
this.vm.attach(root);
|
this.vm.attach(root);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
import { Group } from "../ui/view"
|
import { Group } from "../ui/view"
|
||||||
import { Panel } from "../ui/panel"
|
import { Panel } from "../ui/panel"
|
||||||
|
import { BridgeContext } from "../runtime/global"
|
||||||
|
|
||||||
export abstract class ViewHolder {
|
export abstract class ViewHolder {
|
||||||
abstract build(root: Group): void
|
abstract build(root: Group): void
|
||||||
@ -23,6 +24,7 @@ export abstract class ViewHolder {
|
|||||||
export type Setter<M> = (state: M) => void
|
export type Setter<M> = (state: M) => void
|
||||||
|
|
||||||
export abstract class ViewModel<M extends Object, V extends ViewHolder> {
|
export abstract class ViewModel<M extends Object, V extends ViewHolder> {
|
||||||
|
context!: BridgeContext
|
||||||
private state: M
|
private state: M
|
||||||
private viewHolder: V
|
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 type ClassType<T> = new (...args: any) => T
|
||||||
|
|
||||||
export abstract class VMPanel<M extends Object, V extends ViewHolder> extends Panel {
|
export abstract class VMPanel<M extends Object, V extends ViewHolder> extends Panel {
|
||||||
|
|
||||||
private vm?: ViewModel<M, V>
|
private vm?: ViewModel<M, V>
|
||||||
private vh?: V
|
private vh?: V
|
||||||
|
|
||||||
abstract getViewModelClass(): ClassType<ViewModel<M, V>>
|
abstract getViewModelClass(): ClassType<ViewModel<M, V>>
|
||||||
|
|
||||||
abstract getState(): M
|
abstract getState(): M
|
||||||
@ -74,6 +74,7 @@ export abstract class VMPanel<M extends Object, V extends ViewHolder> extends Pa
|
|||||||
build(root: Group): void {
|
build(root: Group): void {
|
||||||
this.vh = new (this.getViewHolderClass())
|
this.vh = new (this.getViewHolderClass())
|
||||||
this.vm = new (this.getViewModelClass())(this.getState(), this.vh)
|
this.vm = new (this.getViewModelClass())(this.getState(), this.vh)
|
||||||
|
this.vm.context = this.context
|
||||||
this.vm.attach(root)
|
this.vm.attach(root)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user