hwc-stimulus-fundamentals
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseStimulus Fundamentals
Stimulus 核心基础
Implement robust Stimulus controllers with clear lifecycle and state boundaries.
实现具备清晰生命周期和状态边界的健壮Stimulus控制器。
Core Workflow
核心工作流
- Define controller contract first: targets, values, outlets, actions, and expected lifecycle.
- Keep state transitions in value callbacks when reactive updates are required.
- Guard callbacks that can run before completes.
connect() - Use for setup and teardown symmetry.
connect()/disconnect() - Isolate DOM event handling from business rules; keep controllers composable.
- 首先定义控制器契约:targets、values、outlets、动作以及预期的生命周期。
- 当需要响应式更新时,将状态转换放在值回调中。
- 对可能在完成前运行的回调进行防护。
connect() - 使用实现对称的初始化和清理操作。
connect()/disconnect() - 将DOM事件处理与业务逻辑分离;保持控制器的可组合性。
Guardrails
注意准则
- Prefer declarative action parameters over manual dataset parsing.
- Use outlets for controller-to-controller communication instead of private internals.
- Keep target callbacks idempotent; account for repeated connect/disconnect cycles.
- Use MutationObserver only when DOM-driven reactivity is required.
- Feature-detect browser APIs before exposing UI affordances.
- 优先使用声明式动作参数,而非手动解析dataset。
- 使用outlets进行控制器间通信,而非依赖私有内部实现。
- 保持目标回调的幂等性;考虑重复的连接/断开循环。
- 仅当需要DOM驱动的响应性时才使用MutationObserver。
- 在暴露UI功能前先检测浏览器API的支持情况。
Load References Selectively
选择性加载参考资料
Open only the file needed for the current request.
- Value changed callbacks:
references/2023-08-29-stimulus-value-changed-callbacks.md - Keyboard action filters and hotkeys:
references/2023-10-24-stimulus-keyboardevent-101.md - MutationObserver-based sorting:
references/2023-12-05-stimulus-auto-sorting.md - Outlets API communication:
references/2023-12-19-stimulus-outlets-api.md - Target callback orchestration:
references/2024-05-07-stimulus-target-callbacks.md - Web Share API integration:
references/2025-11-25-stimulus-web-share-api.md - Core Web Vitals and lazy-loading fundamentals:
references/2024-06-18-fundamentals-core-web-vitals.md
Use for the full catalog.
references/INDEX.md仅打开当前请求所需的文件。
- 值变更回调:
references/2023-08-29-stimulus-value-changed-callbacks.md - 键盘动作过滤器和热键:
references/2023-10-24-stimulus-keyboardevent-101.md - 基于MutationObserver的排序:
references/2023-12-05-stimulus-auto-sorting.md - Outlets API通信:
references/2023-12-19-stimulus-outlets-api.md - 目标回调编排:
references/2024-05-07-stimulus-target-callbacks.md - Web Share API集成:
references/2025-11-25-stimulus-web-share-api.md - 核心Web指标与懒加载基础:
references/2024-06-18-fundamentals-core-web-vitals.md
使用查看完整目录。
references/INDEX.mdEscalate to Neighbor Skills
关联技能跳转
- Form-centric behavior: use
hwc-forms-validation - Navigation/history/cache with Turbo: use
hwc-navigation-content - Turbo Stream/WebSocket orchestration: use
hwc-realtime-streaming - Media integrations and playback concerns: use
hwc-media-content - UX feedback/transitions/progress concerns: use
hwc-ux-feedback
- 表单相关行为:使用
hwc-forms-validation - Turbo导航/历史/缓存:使用
hwc-navigation-content - Turbo Stream/WebSocket编排:使用
hwc-realtime-streaming - 媒体集成与播放相关:使用
hwc-media-content - UX反馈/过渡/进度相关:使用
hwc-ux-feedback