67 lines
1.4 KiB
TypeScript
67 lines
1.4 KiB
TypeScript
import { ViewHolder, VMPanel, ViewModel, Gravity, Text, VLayout, Group } from "doric"
|
|
|
|
|
|
interface CountModel {
|
|
count: number
|
|
}
|
|
|
|
class CounterView extends ViewHolder {
|
|
number = new Text
|
|
counter = new Text
|
|
build(root: Group) {
|
|
const vlayout = new VLayout
|
|
vlayout.width = 200
|
|
vlayout.height = 200
|
|
vlayout.gravity = new Gravity().center()
|
|
this.number.textSize = 40
|
|
this.number.layoutConfig = {
|
|
alignment: new Gravity().center()
|
|
}
|
|
this.counter = new Text
|
|
this.counter.text = "Click to count"
|
|
this.counter.textSize = 20
|
|
vlayout.space = 20
|
|
vlayout.layoutConfig = {
|
|
alignment: new Gravity().center()
|
|
}
|
|
vlayout.addChild(this.number)
|
|
vlayout.addChild(this.counter)
|
|
root.addChild(vlayout)
|
|
}
|
|
|
|
setNumber(n: number) {
|
|
this.number.text = n.toString()
|
|
}
|
|
|
|
setCounter(v: Function) {
|
|
this.counter.onClick = v
|
|
}
|
|
}
|
|
|
|
class CounterVM extends ViewModel<CountModel, CounterView> {
|
|
|
|
binding(v: CounterView, model: CountModel): void {
|
|
v.setNumber(model.count)
|
|
v.setCounter(() => {
|
|
this.getModel().count++
|
|
})
|
|
}
|
|
}
|
|
|
|
@Entry
|
|
class __$__ extends VMPanel<CountModel, CounterView>{
|
|
|
|
getVMClass() {
|
|
return CounterVM
|
|
}
|
|
|
|
getModel() {
|
|
return {
|
|
count: 0
|
|
}
|
|
}
|
|
|
|
getViewHolder() {
|
|
return new CounterView
|
|
}
|
|
} |