docs: clarify example inheritance and type contract calls
This commit is contained in:
@@ -2,14 +2,18 @@
|
||||
// 同一事件注册机制按实际签名调用;label 绑定再把事件 kind 转成可显示的字符串。
|
||||
// 保留最后一次收到的 Event 对象,初值 kind=waiting;不是只存一份格式化事件文本。
|
||||
received = ui.state(Event("waiting"))
|
||||
// 单独计数的状态与 received 无关,第二个按钮不会改变 eventKind 读取的事件对象。
|
||||
count = ui.state(0)
|
||||
// 只读计算提取当前事件种类,作为 label.text 绑定的依赖。
|
||||
// 由 label.bind 的绑定求值调用,无参数;读取链经过状态 value 再到 Event.kind,返回可显示字符串。
|
||||
function eventKind(): String { return received.value.kind }
|
||||
label = TextBlock("waiting")
|
||||
subscription = label.bind("text", eventKind)
|
||||
// subscription 管理字段绑定,下面两个 Connection 管理输入监听,两种注册的用途不同。
|
||||
withEvent = Button("传递 Event 给原生 set")
|
||||
// received.set 是一参数原生方法,分发器传入实际 click Event。
|
||||
firstConnection = withEvent.on("click", received.set)
|
||||
// 保存的是绑定 count 的原生方法,事件分发按它的零参签名调用,无需人为包装一个丢弃 Event 的函数。
|
||||
withoutEvent = Button("调用零参数原生 increment")
|
||||
// count.increment 的签名为零参数,分发器调用时不传多余 Event。
|
||||
secondConnection = withoutEvent.on("click", count.increment)
|
||||
|
||||
Reference in New Issue
Block a user