stimulus README

The project's README from github.com/hotwired/stimulus. As one markdown file: README.md.

Stimulus Stimulus

A modest JavaScript framework for the HTML you already have

Stimulus is a JavaScript framework with modest ambitions. It doesn't seek to take over your entire front-end—in fact, it's not concerned with rendering HTML at all. Instead, it's designed to augment your HTML with just enough behavior to make it shine. Stimulus pairs beautifully with Turbo to provide a complete solution for fast, compelling applications with a minimal amount of effort.

How does it work? Sprinkle your HTML with controller, target, and action attributes:

<div data-controller="hello">
  <input data-hello-target="name" type="text">

  <button data-action="click->hello#greet">Greet</button>

  <span data-hello-target="output"></span>
</div>

Then write a compatible controller. Stimulus brings it to life automatically:

// hello_controller.js
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  static targets = [ "name", "output" ]

  greet() {
    this.outputTarget.textContent =
      `Hello, ${this.nameTarget.value}!`
  }
}

Stimulus continuously watches the page, kicking in as soon as attributes appear or disappear. It works with any update to the DOM, regardless of whether it comes from a full page load, a Turbo page change, or an Ajax request. Stimulus manages the whole lifecycle.

You can write your first controller in five minutes by following along in the Stimulus Handbook.

You can read more about why we created this new framework in The Origin of Stimulus.

Installing Stimulus

You can use Stimulus with any asset packaging systems. And if you prefer no build step at all, just drop a <script> tag on the page and get right down to business.

See the Installation Guide for detailed instructions.

Getting Help

Looking for the docs? Once you've read through the Handbook, consult the Stimulus Reference for API details.

Have a question about Stimulus? Connect with other Stimulus developers on the Hotwire Discourse community forum.

Contributing Back

Find a bug? Head over to our issue tracker and we'll do our best to help. We love pull requests, too!

We expect all Stimulus contributors to abide by the terms of our Code of Conduct.

Development

Acknowledgments

Stimulus is MIT-licensed open-source software from Basecamp, the creators of Ruby on Rails.


© 2024 Basecamp, LLC.

stimulus (hotwired/stimulus)

Searching Database…

13.1K ·GitHub
这是什么?Stimulus 是一个小型 JavaScript 框架,它为你已有的 HTML 添加交互行为,而不是自己渲染 HTML。
它是像 React 那样完整的前端框架,还是更轻量的东西?它的目标比较克制:不会接管你的前端,也不会渲染 HTML,只是通过 controller、target 和 action 属性为服务端渲染好的现有 HTML 增加功能。
我要怎么把它加到项目里?你可以配合任何资源打包系统使用,也可以完全跳过构建步骤,直接在页面中添加一个 script 标签。
使用它需要依赖其他框架吗?不需要,Stimulus 可以独立使用,但它特别适合与 Turbo 搭配,以较少的工作量构建快速的应用。
它怎么知道什么时候该激活我的控制器?它会持续监视 DOM,只要 controller/target/action 属性出现或消失,就会自动生效,无论这种变化来自整页加载、Turbo 导航还是 Ajax。
它主要是为谁打造的?它出自 Basecamp,也就是 Ruby on Rails 的创造者,适合那些使用服务端渲染 HTML 应用的团队,他们希望为页面点缀一些 JS 交互,而不是彻底重写成单页应用。
我该怎么写第一个控制器?请阅读 Stimulus Handbook,它会用大约五分钟带你写出一个控制器。
除了基础内容,去哪里查看更详细的 API 说明?读完 Handbook 之后,可以查看 Stimulus Reference,里面有详细的 API 文档。
为什么要创建 Stimulus,而不直接用现成的单页应用框架?README 中提到了一篇文章《The Origin of Stimulus》,解释了其中的原因,本质上是倾向于为服务端渲染的 HTML 增加功能,而不是完全依赖客户端渲染。
What are similar projects?impress.js, hono, reactionview, uikit, pico, mitosis, hyperapp, riot
Creator
hotwired
Size
4.1 MB
Stars
13.1K
Age
9y
Commits · 90 Days