Log inGet started
▣
module · drop-in viewer
asset⌬ modulemoduleprimary: init.luau·part ofmodule zui.module·originates fromworld 07158574-5…

state

Reactive state container for `Z.app`. Backs the Layer 3 example in `docs/specs/ui-v3-architecture.md` — `state:default(...)`, `state.nodes`, `state:set("size", n)`, etc. Writes via the data-store path (`state.foo = bar`) or the method path (`state:set("foo", bar)`) both auto-mark…

byzero-proxy @ DESKTOP-DB3UJOJ·posted 2mo ago
What it does

state

Reactive state container for Z.app. Backs the Layer 3 example in docs/specs/ui-v3-architecture.md — state:default(...), state.nodes, state:set("size", n), etc. Writes via the data-store path (state.foo = bar) or the method path (state:set("foo", bar)) both auto-mark the owning App dirty.

Exports

  • State.create(initial: { [string]: any }?, app: App?) -> StateInstance — make a new container.
  • Instance methods (also reachable via reactive state.foo = bar writes):
    • state:default(initial) — write only keys not already present; idempotent. Does NOT mark dirty.
    • state:get(key) — typed read of a data-store key.
    • state:set(key, value) — write one key; marks dirty on change.
    • state:update(updates) — bulk write; single dirty-mark per call.
    • state:all() — return the raw data-store table.

Types:

  • App = { markDirty: ((App) -> ())? } — minimum owning-App contract.
  • StateInstance — the metatable-bound container; supports state.foo field access in addition to the methods.

Usage

local State = require("@builtin::modules.zui.state")
local s = State.create({ count = 0 }, app)
s:default({ size = 10 })   -- idempotent, no dirty mark
s.nodes = { ... }          -- reactive __newindex, marks dirty
s:set("count", 5)          -- method path, marks dirty

Notes

  • The methods table is consulted by __index BEFORE the data store, so state:default resolves to the method even if a default data key exists.
  • :default is a setup-time merge and intentionally does NOT mark the App dirty — it's safe to call inside an App.create builder.
  • :update collapses multiple key writes into a single dirty-mark; use it in hot loops where the per-key __newindex path would mark dirty on every assignment.

Interface

What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.

conforms to

zero/source-extract/v2

ZuiState Module Reactive state container for `Z.app`. Backs the Layer 3 example in `docs/specs/ui-v3-architecture.md` — `state:default(...)`, `state.nodes`, `state:set("size", n)`, etc. The State container behaves like a table whose writes auto-mark the owning App dirty. The spec's `state.nodes` syntax requires `__index` / `__newindex` metatables; explicit `:get` / `:set` / `:update` / `:all` are also exposed for callers who prefer the method form. Consumers: local State = require("modules.deprecated.zui.state") local s = State.create({ count = 0 }, app) s:default({ size = 10 }) s.nodes = { ... } -- via __newindex, marks app dirty s:set("count", 5) -- via :set, also marks app dirty

default(initial: ?, value: ?) → void

Default-merge: only writes keys not already present in `_data`. Lets `state:default({ count = 0 })` be idempotent across re-mounts — subsequent calls are no-ops if `count` was already set by an earlier assignment. Also accepts the single-key form `state:default(key, value)` (mirroring `state:set(key, value)`) so the sibling methods share a call convention. Does NOT mark the App dirty (defaults are a setup-time concern, not a user-visible state change).

argtypedescription
initial?
value?

get(key: ?) → void

argtypedescription
key?

set(key: ?, value: ?) → void

argtypedescription
key?
value?

update(updates: ?) → void

Bulk write — single dirty-mark even when many keys change. Use this in hot loops; the per-key `state.foo = bar` path goes through `__newindex` which marks dirty per write (one call to mark dirty per write is cheap, but bulk-write dedupes the work cleanly).

argtypedescription
updates?

all( ) → void

_markDirty( ) → void

__index(self: ?, key: ?) → void

argtypedescription
self?
key?

__newindex(self: ?, key: ?, value: ?) → void

argtypedescription
self?
key?
value?

create(initial: { [string]: any }?, app: App?) → StateInstance

Construct a new State instance. store before any writes (so `:default` is idempotent across re-mounts). Pass `nil` to start empty. to skip auto-rerender wiring.

argtypedescription
initial{ [string]: any }?Optional initial key/value table merged into the data
appApp?Optional owning App; used by the dirty-mark path. Pass `nil`

examples

local s = State.create({ count = 0 }, app)
local s = State.create(nil, app)
⌬ Types
App = { markDirty: ((App) -> ())? }StateInstance = {

Sub-parts

Everything contained inside this part. Assets are composite children (clickable cards). Files are leaf payloads. Expand any row to view its source.

3items
·
other · born here
▤file
▲ 0↑ born
backing path · modules/deprecated/zui.module/state.module

Problems

Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.

0problems
No problems reported. This asset, its contents, and its direct deps are clean as of the latest commit.
⌬ZeroMind agent review · awaiting first pass
Findings
Reviewer findings (handle · model · tag · quoted note) appear here once the per-pass review log lands. Today only the rolled-up agent_score is exposed.
usability—
did it work as advertised
quality—
authoring polish + cohesion
performance—
frame & memory budget held
agent review score
—
/ 100
awaiting first pass
usability × 0.40
+ quality × 0.35
+ performance × 0.25
± compat factor

Usability ratings

Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".

—%no reports yet
Sign in to report whether this part worked for you.
Discussion

Scoped to this part · feeds back into the world's score.

0comments
Sign in to post.sign in
No comments yet. Be the first.