Loading...
Loading...
Kuikly Reactive Update and Directive System Development Assistant (Kuikly DSL). Guides on how to implement UI reactive updates using observable, observableList, observableSet, and the correct usage of directives such as vfor, vforIndex, vforLazy, vif, velseif, velse, vbind. Use this when you need to handle the following scenarios in Kuikly: (1) Declare reactive fields and bind them to UI attributes (2) List rendering (vfor/vforIndex/vforLazy) (3) Conditional rendering (vif/velseif/velse) (4) Value binding rendering (vbind) (5) Efficient list updates (diffUpdate) (6) Troubleshooting issues like reactive data not taking effect or UI not updating (7) CRUD operations on observableList/observableSet (8) Reactive update strategies for complex objects
npx skill4agent add tencent-tds/kuiklyui-ai kuikly-reactive-observerattr {}Note:usesobservableinternally to compare old and new values, no update is triggered when values are equal.==
PagerPagerScopePagerScope// Recommended: PagerScope extension function
import com.tencent.kuikly.core.reactive.handler.observable
import com.tencent.kuikly.core.reactive.handler.observableList
import com.tencent.kuikly.core.reactive.handler.observableSet
var counter by observable(0) // Single value
var list by observableList<String>() // Reactive list, used with vfor
var tags by observableSet<String>() // Reactive setvar title by observable("Hello")
Text {
attr {
text(ctx.title) // Directly reference the reactive field, automatic binding
}
}
// After updating ctx.title = "World", Text refreshes automaticallyvar list by observableList<String>()
// vfor: Traverse observableList, automatic incremental update when adding or deleting items
List {
attr { flex(1f) }
vfor({ ctx.list }) { item ->
Text { attr { text(item) } }
}
}
// vforIndex: Provides additional index and count
vforIndex({ ctx.list }) { item, index, count ->
View {
attr { backgroundColor(if (index % 2 == 0) Color.GRAY else Color.TRANSPARENT) }
Text { attr { text("$index: $item") } }
}
}Must pass a closure, not directly pass the value{ ctx.list }.ctx.list
ListViewList {
attr { flex(1f) }
vforLazy({ ctx.list }, maxLoadItem = 50) { item, index, count ->
Text { attr { text(item) } }
}
}| Parameter | Type | Default Value | Description |
|---|---|---|---|
| itemList | | — | Data source closure |
| maxLoadItem | | 30 | Maximum number of virtual nodes in memory, recommended to be 2~3 times the number of visible items on one screen |
| itemCreator | | — | Builder closure |
var state by observable(0)
View {
vif({ ctx.state == 1 }) {
Text { attr { text("State 1") } }
}
velseif({ ctx.state == 2 }) {
View { attr { size(100f, 100f); backgroundColor(Color.GREEN) } }
}
velse {
Text { attr { text("Other States") } }
}
}/velseifmust immediately followvelseorvif, no other components can be inserted in between.velseif
whenvar state by observable(0)
View {
vbind({ ctx.state }) {
when (ctx.state) {
1 -> Text { attr { text("State 1") } }
2 -> View { attr { size(100f, 100f); backgroundColor(Color.GREEN) } }
}
}
}When the bound value ofisvbind, the creator closure is not executed.null
// Basic usage (based on Myers diff algorithm, only adds/deletes changed Items)
list.diffUpdate(newData)
// Custom comparison (judge if it's the same element via id)
userList.diffUpdate(newUsers) { old, new -> old.id == new.id }| Method | Behavior | Performance |
|---|---|---|
| Destroys all Items → Rebuilds | Poor |
| Only adds/deletes changed Items | Excellent |