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.
Doric/doric-demo/src/Counter.ts

60 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-01-03 13:35:40 +08:00
import { text, vlayout, ViewHolder, VMPanel, ViewModel, Gravity, NativeCall, Text, Color, log, logw, loge, Group, LayoutSpec, layoutConfig, IVLayout, } from "doric"
2019-12-04 14:07:14 +08:00
interface CountModel {
count: number
}
2019-12-06 11:41:51 +08:00
class CounterView extends ViewHolder {
2019-12-04 14:07:14 +08:00
number!: Text
counter!: Text
build(root: Group) {
2020-01-06 10:43:18 +08:00
vlayout(
[
this.number = text({
textSize: 40,
}),
this.counter = text({
text: "Click To Count",
textSize: 20,
}),
],
{
layoutConfig: layoutConfig().most(),
gravity: Gravity.Center,
space: 20,
}
).in(root)
2019-12-04 14:07:14 +08:00
}
}
class CounterVM extends ViewModel<CountModel, CounterView> {
2019-12-06 11:41:51 +08:00
onAttached(s: CountModel, vh: CounterView) {
2019-12-04 14:07:14 +08:00
vh.counter.onClick = () => {
this.updateState(state => {
state.count++
})
}
}
2019-12-06 11:41:51 +08:00
onBind(s: CountModel, vh: CounterView) {
vh.number.text = `${s.count}`
}
2019-12-04 14:07:14 +08:00
}
@Entry
class MyPage extends VMPanel<CountModel, CounterView>{
getViewHolderClass() {
return CounterView
}
getViewModelClass() {
return CounterVM
}
getState(): CountModel {
return {
count: 0
}
}
}