Refine component APIs and add typed local stores - #3
Merged
Conversation
There was a problem hiding this comment.
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_storeAPIs, 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_actionusespayload.headwithout guarding against an empty payload. If a malformed action message (or decode error upstream) produces an empty payload, this can throw instead of returningNothing, breaking the store protocol’s “safe decode” contract. Add an explicit empty-string guard before accessinghead/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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
store.currentplus typed actionscomponents,on_store_click, andon_store_inputso keyed child scopes and routine store event plumbing stay in the frameworkrender_*collection wrappers and keep only semantic child components/domain calculationsValidation
yarn test:koka: 54 / 54 passyarn build