Skip to content

Instantly share code, notes, and snippets.

@ayb
ayb / stimulus.md
Last active October 22, 2020 15:54 — forked from mrmartineau/stimulus.md
Stimulus cheatsheet

Stimulus cheatsheet

Lifecycle callbacks

  • initialize: once, when the controller is first instantiated
  • connect: anytime the controller is connected to the DOM
  • disconnect: anytime the controller is disconnected from the DOM

Action descriptors

The data-action value click->hello#greet is called an action descriptor. This particular descriptor says:

require 'rubygems'
require 'sinatra'
require 'active_support'
get "/message" do
response = { :Say => "Hello, I am a big monkey" }
response.to_xml(:root => 'Response')
end
post "/message" do