Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commitdd348ac6c3

README.md

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 by Z.app.
  • Dynamic.is(value: any) -> boolean — identify a Z.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 = true tag.

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 = true tag — call Dynamic.is(v) instead of inspecting keys directly.
  • Each item should expose a stable .id field; 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.