Skip to content

Latest commit

 

History

History
81 lines (57 loc) · 4.11 KB

quick-start.md

File metadata and controls

81 lines (57 loc) · 4.11 KB

Component quick start

中文

第一条成功路径不是从 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

从该文件按顺序阅读四个概念即可:

  1. disclosure_action 和 disclosure_action_codec:每个用户 intent 都是可序列化 typed action。
  2. disclosure_store:把 state、codec、reducer 与 snapshot recovery 放在一起。
  3. use_store(..., initial = False):返回熟悉的 (state, dispatch) pair。
  4. feature_root(...) 和 on_store_click(...):声明生命周期边界,并把点击发送为 Toggle_disclosure。

执行 host 故意单独放在 advanced integration 边界:它才导入 renderer、inspection、runtime 和 state helpers,用来渲染、查找 listener、运行 action、再次 render。普通组件无需导入这些模块。

下一步

English

The first success path does not start with the browser runtime. Run one real component:

yarn example:first-component

The 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/react

Read the file in this order to learn four concepts:

  1. disclosure_action and disclosure_action_codec: each user intent is a serializable typed action.
  2. disclosure_store: state, codec, reducer, and snapshot recovery belong together.
  3. use_store(..., initial = False): returns the familiar (state, dispatch) pair.
  4. feature_root(...) and on_store_click(...): declare the lifecycle boundary and send Toggle_disclosure for 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.

Next steps