Token导航 LogoToken导航TokenDH.com
前端设计操作浏览器github未标认证来源可访问许可证需确认审计通过

better-stimulus更好的刺激

Agent Skill

better-stimulus 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

612

周安装

26

GitHub Stars

91

下载量

214
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:better-stimulus(更好的刺激)
来源仓库:https://github.com/obie/skills
仓库路径:skills/better-stimulus
安装命令:
npx skills add https://github.com/obie/skills --skill better-stimulus
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/obie/skills --skill better-stimulus

简介

应用 betterstimulus.com 推荐的 Stimulus 控制器编写规范与 SOLID 设计原则。

  • 强调代码复用、关注点分离与模块化架构,提升前端 JavaScript 可维护性。
  • 适用于新控制器开发、旧代码重构与第三方库集成场景。
  • 使用前应确认项目已采用 Stimulus 框架并理解其生命周期钩子机制。
  • better-stimulus 属于前端设计类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Better Stimulus

Apply opinionated best practices from betterstimulus.com when writing or refactoring Stimulus controllers. These patterns emphasize code reusability, proper separation of concerns, and SOLID design principles.

When to Use This Skill

Invoke this skill when:

  • Writing new Stimulus controllers
  • Refactoring existing Stimulus code
  • Reviewing Stimulus controller architecture
  • Debugging inter-controller communication
  • Integrating third-party JavaScript libraries
  • Implementing form submission logic
  • Managing controller state
  • Setting up Turbo integration

Core Principles

1. Make Controllers Configurable

Externalize hardcoded values into data attributes rather than embedding them in controller logic.

Bad:

toggle() {
  this.element.classList.toggle("active")
}

Good:

static classes = ["active"]
toggle() {
  this.element.classList.toggle(this.activeClass)
}
<div data-controller="toggle" data-toggle-active-class="active"></div>

2. Use Values API for State

Store controller state in Stimulus values, not instance properties, to leverage reactivity and DOM persistence.

Bad:

connect() {
  this.count = 0
}

Good:

static values = { count: Number }
countValueChanged(count) {
  this.updateDisplay()
}

3. Keep Controllers Focused (Single Responsibility)

Each controller should have one reason to change. Split controllers that mix concerns.

Ask: "What would cause this controller to change?" If multiple unrelated reasons, split it.

4. Don't Overuse connect()

Use connect() for:

  • Instantiating third-party plugins (Swiper, Chart.js, etc.)
  • Feature detection/browser capabilities

Don't use connect() for:

  • Setting up state (use Values API)
  • Adding event listeners (use data-action)

5. Register Events Declaratively

Use data-action attributes instead of addEventListener() to let Stimulus manage lifecycle.

Bad:

connect() {
  document.addEventListener("click", this.handler.bind(this))
}

Good:

<div data-action="click@document->controller#handler"></div>

Key Patterns

Architecture

  • Configurable Controllers: Inject dependencies via data attributes
  • Application Controller: Base class for shared functionality
  • Mixins: Share behavior via "acts as" relationships
  • Targetless Controllers: Separate element vs. target manipulation
  • Namespaced Attributes: Handle arbitrary parameter sets

See: references/architecture.md

State Management

  • Use Values API for nearly all state
  • Leverage change callbacks ([name]ValueChanged)
  • Keep values serializable
  • Provide sensible defaults

See: references/state-management.md

Lifecycle

  • Use connect() for third-party library initialization
  • Pair connect() with disconnect() for cleanup
  • Avoid overloading connect() with state setup
  • Implement teardown() for Turbo-specific cleanup

See: references/lifecycle.md

Controller Communication

Three approaches:

  1. Custom Events: Loose coupling, broadcast pattern
  2. Outlets: Direct controller references, structured layouts
  3. Callbacks: Request state from other controllers

Choose based on relationship:

  • Unknown receivers → Custom events
  • Known hierarchy → Outlets
  • Data sharing → Callbacks

See: references/events-and-interaction.md

SOLID Principles

  • Single Responsibility: One reason to change
  • Open-Closed: Extend via inheritance, not modification
  • Dependency Inversion: Depend on abstractions, inject via config

See: references/solid-principles.md

DOM & Turbo

  • Use <template> to restore DOM state
  • Use requestSubmit() not submit() for forms
  • Implement global teardown for Turbo caching
  • Handle Turbo events declaratively

See: references/dom-and-turbo.md

Error Handling

  • Create ApplicationController with handleError() method
  • Integrate with error tracking (Sentry, Honeybadger)
  • Provide user-friendly messages
  • Use try-catch for async operations

See: references/error-handling.md

Quick Reference

Value Types

static values = {
  url: String,
  count: Number,
  enabled: Boolean,
  items: Array,
  config: Object
}

Event Actions

<!-- Element events -->
<div data-action="click->controller#method">

<!-- Global events -->
<div data-action="resize@window->controller#layout">
<div data-action="keydown@document->controller#handleKey">

<!-- Multiple actions -->
<div data-action="click->ctrl1#method1 click->ctrl2#method2">

Custom Events

// Dispatch
const event = new CustomEvent('name:action', {
  bubbles: true,
  detail: { key: 'value' }
})
this.element.dispatchEvent(event)

// Listen
data-action="name:action->controller#handler"

Outlets

<div data-controller="parent"
     data-parent-child-outlet=".child">
  <div class="child" data-controller="child"></div>
</div>
static outlets = ['child']
this.childOutlets.forEach(outlet => outlet.method())

Lifecycle Hooks

connect()           // Element connected to DOM
disconnect()        // Element removed from DOM
[name]TargetConnected(element)      // Target added
[name]TargetDisconnected(element)   // Target removed
[name]ValueChanged(value, oldValue) // Value changed
[name]OutletConnected(outlet)       // Outlet connected
[name]OutletDisconnected(outlet)    // Outlet disconnected

Implementation Workflow

When writing a new controller:

  1. Identify responsibility - What single purpose does this serve?
  2. Choose state approach - Use Values API unless non-serializable
  3. Declare static properties - values, targets, classes, outlets
  4. Implement change callbacks - React to value changes
  5. Keep connect() minimal - Only for third-party setup
  6. Use declarative actions - Avoid addEventListener
  7. Handle errors gracefully - Wrap risky operations in try-catch
  8. Test lifecycle - Verify connect/disconnect behavior

When refactoring:

  1. Check Single Responsibility - Split if multiple concerns
  2. Extract configuration - Move hardcoded values to data attributes
  3. Convert to Values API - Replace instance properties with values
  4. Simplify connect() - Move state and listeners out
  5. Use inheritance/mixins - Share common behavior properly
  6. Decouple controllers - Use events/outlets for communication
  7. Add error handling - Implement handleError from ApplicationController

Common Mistakes to Avoid

  • ❌ Hardcoding CSS classes, selectors, or IDs in controllers
  • ❌ Using instance properties for state instead of values
  • ❌ Overloading connect() with state setup and event listeners
  • ❌ Creating "page controllers" that handle multiple concerns
  • ❌ Using addEventListener() without proper cleanup
  • ❌ Calling .bind() separately in connect and disconnect
  • ❌ Using submit() instead of requestSubmit()
  • ❌ Modifying base classes instead of extending them
  • ❌ Tight coupling between controllers
  • ❌ Swallowing errors without logging or reporting

Resources

All patterns in this skill come from betterstimulus.com, an opinionated collection of StimulusJS best practices.

For detailed explanations and examples, see:

  • references/architecture.md - Controller design patterns
  • references/state-management.md - Values API usage
  • references/lifecycle.md - Lifecycle best practices
  • references/events-and-interaction.md - Communication patterns
  • references/solid-principles.md - SOLID design principles
  • references/dom-and-turbo.md - DOM manipulation and Turbo
  • references/error-handling.md - Error management

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

32.43%
按下载量换算69

Claude

30.96%
按下载量换算66

Cursor

19.88%
按下载量换算43

Gemini CLI

9.72%
按下载量换算21

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

操作浏览器

该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills