Skip to content

简化组件事件中的 domain 与 local-store transition / Simplify domain and local-store transitions in component events #12

Description

@tiye

中文

用户问题

只发送 domain action 或只发送 store action 的组件事件已经很简洁。但 Save 这类事件目前需要 on_local handler 手动传递 domain owner,然后再更新 component store。这种写法正确,却让最重要的组件 transition 比普通 action 更难浏览。

面向用户的目标

让常见的“发送可序列化 domain intent,然后完成或重置本地组件状态”读起来像一个明确的 transition,同时避免为每一种 DOM event 与 target 组合新增 helper。

调研范围

验收标准

  • 至少三个真实调用点共享该 abstraction 后,才将其提升为公共 API。
  • Save/reply 一类组件代码更短,同时 domain action payload 仍保持可见。
  • domain reducer/workflow 仍然不能读取或修改 child stores。
  • transition 保持 action observation order,并且无需浏览器即可测试。
  • 简单的 on_action、on_store 与确实需要定制的 on_local handler 仍然可用。
  • 文档解释何时适合 local coordination,何时应该将 state 提升到 domain model。

非目标

  • 用任意 callback 隐藏可序列化 actions。
  • 为每一种 event kind 增加组合爆炸的 helper。
  • 让业务 reducer 访问 runtime path 或 child state。
  • 在 replay-store 实验明确 session completion 语义前启动这个 API。

English

User problem

A component event that only sends a domain action or only sends a store action is concise. Events such as Save currently need an on_local handler that manually threads the domain owner and then updates the component store. This is correct but makes the most important component transitions harder to scan than ordinary actions.

User-facing goal

Make the common sequence send serializable domain intent, then finish/reset local component state read like one deliberate transition, without introducing a helper for every DOM-event and target combination.

Investigation

Acceptance criteria

  • At least three real call sites share the proposed abstraction before it becomes public API.
  • Save/reply-style component code is shorter and keeps the domain action payload visible.
  • Domain reducer/workflow still cannot read or mutate child stores.
  • The transition preserves action observation order and remains testable without a browser.
  • Simple on_action, on_store, and genuinely custom on_local handlers remain available.
  • Documentation explains when local coordination is appropriate and when state belongs in the domain model.

Non-goals

  • Hiding serializable actions behind arbitrary callbacks.
  • Adding a combinatorial helper for every event kind.
  • Letting business reducers access runtime paths or child state.
  • Starting this API before the replay-store experiment establishes session-completion semantics.

Activity

  1. changed the title [-]Simplify domain and local-store transitions in component events[/-] [+]简化组件事件中的 domain 与 local-store transition / Simplify domain and local-store transitions in component events[/+] on Aug 30, 2026
  2. tiye commented on Aug 30, 2026

    @tiye
    MemberAuthor

    中文

    实现进度

    PR #15 已建立。原型只增加一个与 DOM event 无关的 action_store_transition(...),并迁移四个真实调用点:Todo 开始编辑、保存、取消,以及 Lab 发送回复。Todo 的三段手写 closure 从 15 行收敛为 3 行,Lab 从 5 行收敛为 1 行。

    新增测试直接验证 domain observation 先于 component observation;store_when = False 时仍发送 domain intent,但不推进本地 store。yarn test:koka 70 项通过,yarn check 与浏览器 Todo/Lab 回归通过,浏览器无 warning/error。

    review 时建议重点判断两件事:调用点是否比 owner-threading closure 更容易扫描;store_when 是否足够明确,还是会让业务校验与 reducer 产生难以维护的重复。如果这两点不成立,就不应保留公共 API。

    关联

    English

    Implementation progress

    PR #15 is open. The prototype adds only one DOM-event-independent action_store_transition(...) builder and migrates four real call sites: Todo start, save, and cancel editing, plus Lab send reply. The three Todo handwritten closures shrink from 15 lines to three calls; Lab shrinks from five lines to one call.

    A new test directly verifies that the domain observation precedes the component observation. With store_when = False, the domain intent is still sent while the local store does not advance. All 70 yarn test:koka cases pass; yarn check and the Todo/Lab browser regression pass with no browser warnings or errors.

    The review should focus on two questions: whether the call sites are easier to scan than owner-threading closures, and whether store_when is explicit enough without creating hard-to-maintain validation duplication with the reducer. If either answer is negative, the API should not remain public.

    Links

  3. added
    enhancementNew feature or request
    area: authoring组件作者 API / Component authoring API
    experience: ergonomics日常组件书写体验 / Everyday component ergonomics
    on Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: authoring组件作者 API / Component authoring APIenhancementNew feature or requestexperience: ergonomics日常组件书写体验 / Everyday component ergonomicsstatus: shipped已经合并 / Already merged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions