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, а лишь дополняет уже отрендеренный на сервере HTML с помощью атрибутов controller, target и action.
Как добавить его в проект?Можно использовать любую систему сборки ассетов или вовсе обойтись без сборки и просто подключить тег script на странице.
Нужен ли мне другой фреймворк, чтобы им пользоваться?Нет, Stimulus работает самостоятельно, но особенно хорошо сочетается с Turbo, позволяя с минимальными усилиями создавать быстрые приложения.
Как он понимает, когда активировать мои контроллеры?Он постоянно следит за DOM и автоматически активируется, как только появляются или исчезают атрибуты controller, target и action, независимо от того, произошло ли изменение при полной загрузке страницы, навигации через Turbo или Ajax.
Для кого он в первую очередь создан?Он создан в Basecamp, компании, которая также стоит за Ruby on Rails, и подходит командам, разрабатывающим приложения с HTML, отрендеренным на сервере, которым нужно добавить немного JS-поведения, а не переписывать всё в виде одностраничного приложения (SPA).
Как написать свой первый контроллер?Следуйте руководству Stimulus Handbook, в котором за пять минут объясняется, как написать контроллер.
Где найти подробности API, выходящие за рамки основ?Прочитав Handbook, загляните в Stimulus Reference, где подробно описан API.
Почему Stimulus создали, а не использовали готовый SPA-фреймворк?В 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