effectorjs

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

EffectorJS Skill

EffectorJS 技能

Use this skill to produce deterministic, scope-safe Effector solutions for new features, refactors, and code reviews.
使用本技能为新功能、重构和代码评审生成确定性的、作用域安全的Effector解决方案。

Workflow

工作流程

  1. Classify the request:
  • modeling
    : create or extend stores/events/effects.
  • refactor
    : replace anti-patterns with declarative flows.
  • ssr
    : implement or debug scope-safe SSR.
  • review
    : assess risks, regressions, and missing tests.
  • legacy-migration
    : move old patterns to modern v23+ safely.
  1. Load only required references:
  • Always start with
    references/core-patterns.md
    .
  • Always load
    references/lint-derived-best-practices.md
    after core patterns to enforce plugin-backed best practices.
  • Add
    references/explicit-start.md
    when task touches app bootstrap, startup logic, initialization order, tests, scope, or SSR.
  • Add
    references/computation-priority.md
    when task touches ordering,
    watch
    , sequencing, race-like behavior, or side effects placement.
  • Add
    references/react-ssr-scope.md
    when React/SSR/scope appears.
  • Add
    references/solid-scope.md
    when Solid integration appears.
  • Add
    references/vue-scope.md
    when Vue integration appears.
  • Add
    references/anti-patterns-and-fixes.md
    when fixing or reviewing existing logic.
  • Add
    references/legacy-migration-map.md
    when deprecated APIs/imports are present.
  • End with
    references/checklists.md
    for acceptance criteria.
  1. Build solution in this order:
  • Model atomic stores and explicit events.
  • Define explicit app start (
    appStarted
    ) and keep startup wiring declarative.
  • Move side effects to effects.
  • Connect units with
    sample
    first; use
    attach
    for effect composition.
  • Apply scope-first rules (
    fork
    ,
    allSettled
    ) for tests, SPA bootstrap boundaries, and SSR.
  • For UI frameworks, use
    useUnit
    and correct provider wiring.
  1. Produce output contract:
  • Proposed model topology (stores/events/effects and responsibilities).
  • Wiring snippets (
    sample
    ,
    attach
    ,
    split
    if needed).
  • Scope/SSR notes when applicable.
  • Lint-derived conformance notes for naming/dataflow/scope/react constraints.
  • Test scenarios and acceptance checklist.
  1. 对请求进行分类:
  • modeling
    :创建或扩展stores/events/effects。
  • refactor
    :用声明式流替换反模式。
  • ssr
    :实现或调试作用域安全的SSR。
  • review
    :评估风险、回归问题和缺失的测试。
  • legacy-migration
    :将旧模式安全迁移到现代v23+版本。
  1. 仅加载必要的参考资料:
  • 始终从
    references/core-patterns.md
    开始。
  • 在核心模式之后,始终加载
    references/lint-derived-best-practices.md
    以强制执行基于插件的最佳实践。
  • 当任务涉及应用启动、启动逻辑、初始化顺序、测试、作用域或SSR时,添加
    references/explicit-start.md
  • 当任务涉及执行顺序、
    watch
    、序列处理、类竞争行为或副作用放置时,添加
    references/computation-priority.md
  • 当涉及React/SSR/作用域时,添加
    references/react-ssr-scope.md
  • 当涉及Solid集成时,添加
    references/solid-scope.md
  • 当涉及Vue集成时,添加
    references/vue-scope.md
  • 当修复或评审现有逻辑时,添加
    references/anti-patterns-and-fixes.md
  • 当存在已弃用的API/导入时,添加
    references/legacy-migration-map.md
  • 最后加载
    references/checklists.md
    作为验收标准。
  1. 按以下顺序构建解决方案:
  • 建模原子化stores和显式events。
  • 定义显式的应用启动(
    appStarted
    )并保持启动连线为声明式。
  • 将副作用迁移到effects中。
  • 首先使用
    sample
    连接单元;使用
    attach
    进行effect组合。
  • 对测试、SPA启动边界和SSR应用“作用域优先”规则(
    fork
    allSettled
    )。
  • 对于UI框架,使用
    useUnit
    和正确的提供者连线。
  1. 生成输出约定:
  • 提议的模型拓扑(stores/events/effects及其职责)。
  • 连线代码片段(
    sample
    attach
    、必要时使用
    split
    )。
  • 适用时的作用域/SSR说明。
  • 基于Lint的命名/数据流/作用域/React约束合规性说明。
  • 测试场景和验收检查清单。

Defaults

默认规则

  • Target Effector modern v23+.
  • Treat deprecated/legacy patterns as migration targets, not defaults.
  • Prefer minimal, explicit unit graph over clever abstractions.
  • Treat lint-derived practices from
    eslint-plugin-effector
    as baseline constraints.
  • Use glossary-consistent terminology in explanations and reviews.
  • 目标为现代Effector v23+版本。
  • 将已弃用/旧版模式视为迁移目标,而非默认选项。
  • 优先选择最小化、显式的单元图,而非复杂的抽象。
  • eslint-plugin-effector
    衍生的Lint实践视为基线约束。
  • 在解释和评审中使用与术语表一致的术语。

Glossary Alignment (Effector)

术语表对齐(Effector)

  • Unit
    : include
    Store
    ,
    Event
    ,
    Effect
    ,
    Domain
    ,
    Scope
    .
  • Common unit
    : only
    Store
    ,
    Event
    ,
    Effect
    (reactive update sources for many APIs).
  • Derived store
    : read-only store built from other stores (
    map
    ,
    combine
    , effect-derived stores like
    .pending
    ).
  • Derived store
    constraints: do not mutate directly and do not use as
    target
    in
    sample
    .
  • Reducer
    :
    store.on(...)
    handlers must return next state;
    undefined
    or same reference (
    ===
    ) means no store update.
  • Watcher
    : side effects/debug observability only; watcher return value is ignored.
  • Subscription
    : treat unsubscribe handlers as infrastructure concern; avoid manual subscription management in business logic.
  • Purity
    : pure functions (
    map
    ,
    .on
    , transform callbacks) must not imperatively call events/effects.
  • Domain
    : namespace for units;
    onCreate*
    hooks are acceptable for infra-level cross-cutting concerns (logging/instrumentation), not business orchestration.
  • Unit
    :包括
    Store
    Event
    Effect
    Domain
    Scope
  • Common unit
    :仅指
    Store
    Event
    Effect
    (许多API的响应式更新源)。
  • Derived store
    :基于其他store构建的只读store(
    map
    combine
    、effect衍生的store如
    .pending
    )。
  • Derived store
    约束:不得直接修改,也不得在
    sample
    中作为
    target
    使用。
  • Reducer
    store.on(...)
    处理函数必须返回下一个状态;返回
    undefined
    或相同引用(
    ===
    )表示不更新store。
  • Watcher
    :仅用于副作用/调试可观测性;忽略watcher的返回值。
  • Subscription
    :将取消订阅处理视为基础设施相关事项;避免在业务逻辑中手动管理订阅。
  • Purity
    :纯函数(
    map
    .on
    、转换回调)不得命令式调用events/effects。
  • Domain
    :单元的命名空间;
    onCreate*
    钩子可用于基础设施层面的横切关注点(日志/监控),而非业务编排。

Guardrails

防护规则

  • Do not place business logic in
    watch
    .
  • Prefer
    sample
    over
    forward
    /
    guard
    for orchestration.
  • Respect computation priority: keep
    map
    /
    .on
    pure and avoid side effects in pure computation stages.
  • Do not call events/effects imperatively from effect bodies when declarative wiring can express the flow.
  • Do not use
    $store.getState()
    for business dataflow; pass state through
    sample
    source.
  • Do not use derived stores as
    target
    in
    sample
    ; target writable units/events/effects only.
  • Keep
    sample
    /
    guard
    options in semantic order:
    clock -> source -> filter -> fn -> target
    .
  • Avoid ambiguous
    target
    usage (no simultaneous result assignment and explicit
    target
    ).
  • Avoid duplicate units in
    clock
    /
    source
    arrays and duplicate
    .on
    handlers for one store-event pair.
  • Do not use
    sample
    /
    guard
    without runtime effect (must have target or captured result).
  • Do not create units dynamically at runtime.
  • Keep naming explicit (
    $store
    ,
    eventHappened
    ,
    someFx
    ).
  • In React, bind callable units with
    useUnit
    ; avoid raw event/effect usage in JSX handlers.
  • 不得在
    watch
    中放置业务逻辑。
  • 编排时优先使用
    sample
    而非
    forward
    /
    guard
  • 遵循计算优先级:保持
    map
    /
    .on
    的纯函数特性,避免在纯计算阶段产生副作用。
  • 当声明式连线可以表达流时,不得从effect体中命令式调用events/effects。
  • 不得使用
    $store.getState()
    进行业务数据流处理;通过
    sample
    的source传递状态。
  • 不得将衍生store作为
    sample
    中的
    target
    ;仅以可写单元/events/effects为目标。
  • 保持
    sample
    /
    guard
    选项的语义顺序:
    clock -> source -> filter -> fn -> target
  • 避免模糊的
    target
    使用(不得同时进行结果赋值和显式指定
    target
    )。
  • 避免在
    clock
    /
    source
    数组中出现重复单元,以及同一个store-event对存在重复的
    .on
    处理函数。
  • 不得使用没有运行时效果的
    sample
    /
    guard
    (必须有target或捕获的结果)。
  • 不得在运行时动态创建单元。
  • 保持命名明确(
    $store
    eventHappened
    someFx
    )。
  • 在React中,使用
    useUnit
    绑定可调用单元;避免在JSX处理函数中直接使用原始的event/effect。

Legacy Handling

遗留代码处理

If legacy code is present:
  1. Keep behavior unchanged first.
  2. Mark legacy section explicitly.
  3. Propose modern replacement with a migration-safe diff strategy.
  4. Add tests that prove parity before cleanup.
如果存在遗留代码:
  1. 首先保持行为不变。
  2. 显式标记遗留代码部分。
  3. 提出带有安全迁移差异策略的现代替代方案。
  4. 在清理前添加证明功能一致性的测试。