第一条成功路径不是从 browser runtime 开始,而是运行一个真实组件:
yarn example:first-component命令会编译并执行 示例组件,再在内存中触发一次注册的 click listener。成功输出在一屏内包含:
Initial UI: ... State: closed ... Show answer ...
Typed action: Toggle_disclosure example/disclosure-action@1 payload=toggle
Updated UI: ... State: open ... Hide answer ...
这是教程唯一的实现来源;文档不再复制另一份 FAQ 代码。组件文件只使用:
import explore/react从该文件按顺序阅读四个概念即可:
disclosure_action和disclosure_action_codec:每个用户 intent 都是可序列化 typed action。disclosure_store:把 state、codec、reducer 与 snapshot recovery 放在一起。use_store(..., initial = False):返回熟悉的(state, dispatch)pair。feature_root(...)和on_store_click(...):声明生命周期边界,并把点击发送为Toggle_disclosure。
执行 host 故意单独放在 advanced integration 边界:它才导入 renderer、inspection、runtime 和 state helpers,用来渲染、查找 listener、运行 action、再次 render。普通组件无需导入这些模块。
- Component author API:一页内查看推荐 surface 和选择规则。
- Component 错误与诊断 cookbook:按 Koka 编译错误、框架边界和恢复诊断找到最小修复。
- Store recovery:何时选择 snapshot_store 或 replay_store。
- Component lifecycle:ordinary child 与 persistent feature 的清理/保留语义。
- Effect lifecycle:effect/resource 的 setup、cleanup 与 HMR 顺序。
- Action/store transitions:同一事件如何协调 domain intent 与 component store。
The first success path does not start with the browser runtime. Run one real component:
yarn example:first-componentThe command compiles and executes the example component, then triggers one registered click listener in memory. Its one-screen success output includes:
Initial UI: ... State: closed ... Show answer ...
Typed action: Toggle_disclosure example/disclosure-action@1 payload=toggle
Updated UI: ... State: open ... Hide answer ...
This is the tutorial's only implementation source; the documentation no longer copies a second FAQ implementation. The component file uses only:
import explore/reactRead the file in this order to learn four concepts:
disclosure_actionanddisclosure_action_codec: each user intent is a serializable typed action.disclosure_store: state, codec, reducer, and snapshot recovery belong together.use_store(..., initial = False): returns the familiar(state, dispatch)pair.feature_root(...)andon_store_click(...): declare the lifecycle boundary and sendToggle_disclosurefor the click.
The executable host deliberately lives at the advanced-integration boundary. It alone imports renderer, inspection, runtime, and state helpers to render, find the listener, run the action, and render again. Ordinary components do not need those modules.
- Component author API: recommended surface and selection rules on one page.
- Component error and diagnosis cookbook: find minimal fixes by Koka error, framework boundary, or recovery symptom.
- Store recovery: when to choose snapshot_store or replay_store.
- Component lifecycle: cleanup/preservation semantics for ordinary children and persistent features.
- Effect lifecycle: effect/resource setup, cleanup, and HMR order.
- Action/store transitions: coordinate a domain intent and component store in one event.