reatom-async
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseReatom Async
Reatom Async
Use this skill when the task is mainly about Reatom async behavior. Treat REFERENCE.md as the bundled async source of truth.
当任务主要涉及Reatom异步行为时使用此技能。将REFERENCE.md视为权威的异步参考文档。
How to Use
使用方法
- Read only the REFERENCE.md sections that match the task.
- Prefer Reatom async patterns over debounce libraries, mount-time fetches, refs, local component promise state, or manual AbortController bookkeeping.
- For general Reatom modeling, use the skill. For
reatomDOM JSX specifics, use@reatom/jsx. For reviews, combine this skill withreatom-jsx.reatom-review - If docs, source, and tests disagree, prefer source and tests, then fix the doc/example that is stale.
- 仅阅读REFERENCE.md中与任务匹配的章节。
- 优先使用Reatom异步模式,而非防抖库、挂载时请求、refs、本地组件Promise状态或手动管理AbortController。
- 通用Reatom建模请使用技能。针对
reatomDOM JSX的特定场景,请使用@reatom/jsx。评审时,请将此技能与reatom-jsx结合使用。reatom-review - 若文档、源码和测试内容不一致,优先以源码和测试为准,然后修复过时的文档/示例。
Section Map
章节映射
- Queries and mutations: ,
Choosing the Primitive,withAsyncDatawithAsync - Context after :
awaitwrap Rules - Cancellation: ,
withAbortabortVar and Fetch Signals - Debounce, throttle, waits, races:
Sampling and Procedural Async - Redux-saga migration:
Redux-Saga Mapping - Loading UI and retry:
Status, Retry, Reset - Suspense:
Suspense Boundaries - Code review: ,
Common MistakesTested Edge Cases
- 查询与变更:、
Choosing the Primitive、withAsyncDatawithAsync - 后的上下文:
awaitwrap Rules - 取消操作:、
withAbortabortVar and Fetch Signals - 防抖、节流、等待、竞态:
Sampling and Procedural Async - Redux-saga迁移:
Redux-Saga Mapping - 加载UI与重试:
Status, Retry, Reset - Suspense:
Suspense Boundaries - 代码评审:、
Common MistakesTested Edge Cases
Implementation Defaults
实现默认规范
- Query/read data: .
computed(async () => ...).extend(withAsyncData({ initState })) - Command/mutation: ; add
action(async () => ...).extend(withAsync(...))when stale calls must stop.withAbort(...) - Every async boundary that leaves a Reatom frame uses .
await wrap(promise) - External callbacks that call Reatom state/actions are passed as or wired with
wrap(fn).onEvent - Abortable fetches use or a scoped
signal: abortVar.require().signal.abortVar.subscribe() - Debounce and throttle follow the sampling docs: inside the flow plus
await wrap(sleep(ms))strategies, not split debounce helpers.withAbort() - Route/page data belongs in route loaders or async computeds, not component effects.
- Form submit is an async mutation: put it in and use field
reatomForm({ onSubmit })for async/dependent checks (debounce withvalidate), instead of hand-rolled submit actions or debounced validators.await wrap(sleep(ms)) - Suspense is for global one-shot initialization, not dynamic page data.
- 查询/读取数据:。
computed(async () => ...).extend(withAsyncData({ initState })) - 命令/变更:;当需要终止过时调用时,添加
action(async () => ...).extend(withAsync(...))。withAbort(...) - 所有离开Reatom执行帧的异步边界均使用。
await wrap(promise) - 调用Reatom状态/动作的外部回调需以形式传入,或通过
wrap(fn)连接。onEvent - 可取消的请求使用或作用域化的
signal: abortVar.require().signal。abortVar.subscribe() - 防抖和节流遵循采样文档:在流内部使用,结合
await wrap(sleep(ms))策略,而非单独的防抖工具。withAbort() - 路由/页面数据应放在路由加载器或异步computed中,而非组件effect。
- 表单提交是异步变更:将其放入,使用字段
reatomForm({ onSubmit })进行异步/依赖校验(通过validate实现防抖),而非手动编写提交动作或防抖校验器。await wrap(sleep(ms)) - Suspense适用于全局一次性初始化,而非动态页面数据。
Review Defaults
评审默认规范
- Flag unwrapped awaits before atom/action calls.
- Flag used for query data where
withAsyncshould ownwithAsyncData..data - Flag without
withAsyncwhen stale command calls can update state.withAbort - Flag without
.status().{ status: true } - Flag action without
.retry().{ cacheParams: true } - Flag before
withCache()/withAsync().withAsyncData() - Flag aborts displayed as business errors.
- Flag raw when loser cleanup is needed.
Promise.race
- 标记在atom/动作调用前未被wrap的await。
- 标记在查询数据场景中使用而非
withAsync管理withAsyncData的情况。.data - 标记当过时命令调用可能更新状态时,未搭配的
withAbort。withAsync - 标记未传入的
{ status: true }调用。.status() - 标记未传入的action
{ cacheParams: true }调用。.retry() - 标记在/
withAsync()之前使用withAsyncData()的情况。withCache() - 标记将取消操作显示为业务错误的情况。
- 标记当需要清理失败方时使用原生的情况。
Promise.race