Skip to content

Refine component APIs and add typed local stores - #3

Merged
tiye merged 4 commits into
mainfrom
codex/typed-component-store
Aug 23, 2026
Merged

Refine component APIs and add typed local stores#3
tiye merged 4 commits into
mainfrom
codex/typed-component-store

Conversation

@tiye

@tiye tiye commented Aug 23, 2026

Copy link
Copy Markdown
Member

Summary

  • streamline vnode and component calls with labelled arguments
  • add typed reducer-backed component stores over versioned schema/payload cells
  • expose serializable action envelopes and migrate Todo and Lab local state to store.current plus typed actions
  • add components, on_store_click, and on_store_input so keyed child scopes and routine store event plumbing stay in the framework
  • handle local-state reads/writes once at the event runtime boundary; remove runtime-tree attach/detach helpers and the framework tree field from the business model
  • preserve component-state snapshots across reloads and Vite HMR while rebuilding effect metadata
  • validate URI-decoded snapshot entries and make state/action codecs reject malformed empty payloads safely
  • coalesce event-driven localStorage writes per animation frame while forcing final flushes for HMR and page close
  • stage Koka output and copy only changed generated modules to avoid invalid HMR intermediate states
  • inline one-line render_* collection wrappers and keep only semantic child components/domain calculations
  • update README, developer guidance, and the implementation plan for flattened elements, typed stores/actions, runtime ownership, and snapshot recovery

Validation

  • yarn test:koka: 54 / 54 pass
  • yarn build
  • browser regression: Todo edit/save; Lab draft/expand/action flow; rapid input survives immediate close/reopen; state survives route changes and localStorage restoration; no browser warnings/errors

Copilot AI lite review requested due to automatic review settings August 23, 2026 15:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refines the Koka “explore/react” component surface by moving to flatter, labelled-argument VDOM helpers, introducing typed reducer-backed local stores over versioned schema/payload state cells, and persisting component-state snapshots across reloads and Vite HMR while keeping effect metadata rebuildable.

Changes:

  • Added schema/versioned local state entries plus typed store_spec/use_store APIs, action envelopes, and snapshot encode/decode utilities.
  • Updated demos and libraries to the new element helper API (positional children/text + labelled attrs/events) and migrated the todo editor to editor.current + editor.send(Action).
  • Improved dev/HMR behavior by staging Koka build output and preserving/restoring component-state snapshots through reload/HMR.

Reviewed changes

Copilot reviewed 23 out of 24 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/main.js Installs dispatch bridges that persist/restores runtime state snapshots and reboots Koka runtime on HMR updates.
scripts/build-koka.mjs Stages Koka output in a temp directory and copies only changed generated modules to keep Vite HMR stable.
library/search.kk Migrates search UI nodes to the new labelled-argument element helpers.
library/dialog.kk Updates dialog rendering to new element helpers and labelled arguments for clearer call sites.
library/bridge.kk Updates bridge demo rendering to new element helpers and listener helpers.
explore/react/state.kk Introduces schema/versioned local state cells, typed stores/actions, and snapshot encode/decode; updates hook APIs.
explore/react/core.kk Replaces props/on record APIs with flatter element helpers using labelled arguments and “extra_*” escape hatches.
demo/todo/view.kk Migrates todo UI to new element helpers and switches task editor local state to typed use_store.
demo/todo/state.kk Adds task editor reducer + codecs and store spec; updates scope/path helpers to semantic names.
demo/testspanel.kk Updates tests panel VDOM to new element helpers and updated panel(...) API.
demo/tests/todocases.kk Adds protocol test for typed store/action encoding plus snapshot roundtrip behavior; updates effect path assertions.
demo/tests/statecases.kk Updates local-state tests to semantic named state/effect/listener paths and implicit codec APIs.
demo/tests/basics.kk Updates render snapshot test to the new button(...) helper signature.
demo/tests.kk Registers the new todo editor store protocol test in the test list.
demo/shared.kk Updates panel(...) and summary chip helpers to new labelled-argument element helpers and new parameter order.
demo/routebar.kk Migrates route bar UI nodes to new element helpers.
demo/layout.kk Migrates layout nodes to new element helpers; updates shell section construction.
demo/lab/view.kk Migrates lab UI nodes to new element helpers and semantic local state usage.
demo/lab/state.kk Updates lab local state read/write helpers to semantic named state paths and APIs.
demo/effectspanel.kk Migrates effects panel UI nodes to new element helpers and updated case naming.
demo/dialogs.kk Migrates dialogs demo to labelled arguments and semantic effect naming for focus management.
boilerplate/browserapp.kk Adds snapshot export and boot-with-snapshot entrypoints; boot now delegates to snapshot-aware boot.
app.kk Exposes boot_with_snapshot and export_state_snapshot_bridge through the app entry module.
.gitignore Ignores staged Koka output directory and .DS_Store.
Suppressed comments (1)

demo/todo/state.kk:46

  • decode_task_editor_action uses payload.head without guarding against an empty payload. If a malformed action message (or decode error upstream) produces an empty payload, this can throw instead of returning Nothing, breaking the store protocol’s “safe decode” contract. Add an explicit empty-string guard before accessing head/tail.
fun decode_task_editor_action(version : int, payload : string) : maybe<task_editor_action>
  if version != 1 then Nothing
  else if payload.head == "b" then Just(Begin_edit(payload.tail))
  else if payload.head == "d" then Just(Change_draft(payload.tail))
  else if payload.head == "c" then Just(Cancel_edit(payload.tail))
  else if payload == "f" then Just(Finish_edit)
  else Nothing

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread demo/todo/state.kk
Comment thread explore/react/state.kk
Comment thread src/main.js
@tiye
tiye merged commit 0888903 into main Aug 23, 2026
1 check passed
@tiye
tiye deleted the codex/typed-component-store branch August 23, 2026 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants