▣
module · drop-in viewer
dynamic
`Z.dynamic(list, fn)` — one screen per list item. The `Z.app` mount/tick loop recognises the wrapper and registers `<base>-<item.id>` screens; on every tick it diffs against the previously-registered ids and unregisters screens whose items disappeared.
by·posted 2mo ago
What it does
dynamic
Z.dynamic(list, fn) — one screen per list item. The Z.app mount/tick
loop recognises the wrapper and registers <base>-<item.id> screens;
on every tick it diffs against the previously-registered ids and
unregisters screens whose items disappeared.
Exports
Dynamic.create(list: { any }, fn: (any, number) -> any) -> Wrapper— build a dynamic-list bucket consumed byZ.app.Dynamic.is(value: any) -> boolean— identify aZ.dynamic(...)wrapper.Dynamic.itemId(item: any, index: number) -> string— derive a stable per-item id (falls back to the array index).
Types:
Wrapper = { list, fn, ... }— opaque wrapper carrying the__zuiDynamic = truetag.
Usage
local Dynamic = require("@builtin::modules.zui.dynamic")
local Z = require("@builtin::modules.zui")
return Z.app("inventory", function(state)
return {
items = Z.dynamic(state.items, function(item, index)
return Z.lbl(item.label)
end),
}
end)
Notes
- The wrapper carries an internal
__zuiDynamic = truetag — callDynamic.is(v)instead of inspecting keys directly. - Each item should expose a stable
.idfield; without one, the screen name uses the array index, which makes ordering changes feel like add/remove events. - The list is read by reference on every tick — mutating it between ticks is the normal way to drive add/remove/reorder.
- Unregistration is automatic: when an item disappears from the list, its per-item screen is unregistered on the next tick.
Discussion
Scoped to this part · feeds back into the world's score.
Sign in to post.sign in
No comments yet. Be the first.