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/js-framework/demo.ts

54 lines
1.3 KiB
TypeScript
Raw Normal View History

2019-07-24 16:38:34 +08:00
import { VMPanel, View, ViewModel, WRAP_CONTENT, Gravity, Mutable, NativeCall, Text, Color, VLayout, Panel, log, logw, loge, Group, Stack, } from "./index"
import { CENTER } from "./src/util/gravity";
2019-07-18 16:29:24 +08:00
2019-07-24 16:38:34 +08:00
interface CountModel {
count: number
}
2019-07-18 20:11:01 +08:00
2019-07-24 16:38:34 +08:00
class CounterVM extends ViewModel<CountModel> {
build(root: Group, model: CountModel) {
const vlayout = new VLayout
const number = new Text
number.textSize = 40
number.layoutConfig = {
alignment: new Gravity().center()
2019-07-23 13:01:45 +08:00
}
2019-07-24 16:38:34 +08:00
const counter = new Text
counter.text = "点击计数"
counter.textSize = 20
2019-07-24 11:43:38 +08:00
2019-07-24 16:38:34 +08:00
vlayout.space = 20
vlayout.layoutConfig = {
alignment: new Gravity().center()
2019-07-24 11:43:38 +08:00
}
2019-07-24 16:38:34 +08:00
vlayout.addChild(number)
vlayout.addChild(counter)
root.addChild(vlayout)
2019-07-24 11:43:38 +08:00
2019-07-24 16:38:34 +08:00
this.bind((data) => {
number.text = data.count.toString()
loge(`data changed:${data.count},${vlayout.isDirty()}`)
})
counter.onClick = () => {
model.count++
loge('onclick', model.count)
2019-07-24 10:14:17 +08:00
}
2019-07-24 16:38:34 +08:00
}
}
@Entry
class MyPage extends VMPanel<CountModel>{
createVM(): ViewModel<CountModel> {
return new CounterVM({ count: 0 })
2019-07-18 16:29:24 +08:00
}
2019-07-22 14:36:32 +08:00
2019-07-22 13:41:38 +08:00
@NativeCall
2019-07-18 16:29:24 +08:00
log() {
2019-07-22 13:41:38 +08:00
log("Hello.HEGO")
logw("Hello.HEGO")
loge("Hello.HEGO")
2019-07-18 16:29:24 +08:00
}
}