nustack
NudleComponents

CheckboxRef

Boolean toggle. Tab-owned: the browser holds the canonical checked state.

kind

input

defaults (class-level)

fieldtypedefaultnotes
labelstr""text next to the box; empty means no label, box only.
checkedboolFalseinitial checked state seeded on mount.

Class attributes on the python CheckboxRef. Shipped on mount under the field entry's props key and used to seed the slice. Later server -> tab writes override the slice value.

interactions

opdirpayloadnu methodnotes
writeserver -> tabboolstorecanonical push or reset; replaces the local checked state.
readserver -> tabrequest null; resp bool(via aeval)request/response, correlated by id. resolves the live value.
notifytab -> servernullchangedemitted on every user toggle of the box or its label.

CheckboxRef.aeval ships a read via session.aread and returns the bool. CheckboxRef.store(value) compiles to write. CheckboxRef.changed() is the standard Changed subscription.

wire payloads

// mount field entry (inside the mount payload)
{"path": "HomePage.agree", "type": "CheckboxRef", "props": {"label": "I agree", "checked": false}}

// server pushes a value
{"op": "write",  "ref": "HomePage.agree", "payload": true}

// server fetches
{"op": "read",   "ref": "HomePage.agree", "payload": null, "id": "ab12"}
{"op": "read",   "ref": "HomePage.agree", "payload": true, "id": "ab12"}

// browser tells server the user toggled
{"op": "notify", "ref": "HomePage.agree", "payload": null}

write and read-response payloads are msgpack bools. notify and read-request payloads are msgpack nil.

renderer

web/src/refs/checkbox.tsx. Native <input type="checkbox"> wrapped in a <label> so the label text is also a click target. Tailwind utility classes; no shadcn dep.

slice shape

{
  type: "CheckboxRef",
  value: null,
  label: string,
  checked: boolean,
  write: (v: unknown) => void,
  get: () => boolean,
}

Seeded from field.props on mount. write coerces non-bool / nil payloads via Boolean(v). get reads the live slice to avoid stale closures.

edge cases

  • write payload is msgpack nil (Nu sentinel): coerced to false.
  • write payload is non-bool: Boolean(v) coercion; no error frame.
  • slot never written and no props on mount: slice defaults to checked=false, label="".
  • empty label: the trailing <span> is omitted; only the box is clickable.
  • no debounce: each user toggle emits one notify.

On this page