Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Stimulusのすすめ/Introduction to Stimulus
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
thatblue
July 25, 2025
Programming
58
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Stimulusのすすめ/Introduction to Stimulus
Sendai.rb #43 での発表資料です。
https://sendairb.connpass.com/event/358845/
thatblue
July 25, 2025
More Decks by thatblue
See All by thatblue
Kaigi on Rails 2025 お土産話 / Trip Stories of Kaigi on Rails 2025
thatblue
0
62
RubyKaigi 2025 お土産話 / Trip Stories of RubyKaigi 2025
thatblue
0
36
発表資料テンプレート / My slide template
thatblue
0
690
GitHub Pagesで構築したブログをスマホ対応させてみた / make mobile-compatible with lightweight css framework
thatblue
0
500
Sendai.rbコミュニティ紹介 2022 / Introduction of Sendai.rb 2022
thatblue
0
120
Rails Girls Sendaiコミュニティ紹介2022 / Introduction of Rails Girls Sendai 2022
thatblue
0
150
競技プログラミングへのお誘い~私と競プロ友達になってください / Invitation to Competition Programming
thatblue
1
880
好みのコーヒー探し / find my favorite coffee
thatblue
0
790
Rails Girls Sendai 2ndの後日談としてのSendai.rb / Sendai.rb, As a After Story of Rails Girls Sendai 2nd
thatblue
0
110
Other Decks in Programming
See All in Programming
エンジニア向け会社紹介/Findy Company Profile
findyinc
6
360k
Lessons from Spec-Driven Development
simas
PRO
0
230
1B+ /day規模のログを管理する技術
broadleaf
0
120
自作OSでスライド発表する
uyuki234
0
2.8k
Performance Engineering for Everyone
elenatanasoiu
0
240
はてなアカウント基盤 State of the Union
cockscomb
1
1.2k
スマートグラスで並列バイブコーディング
hyshu
0
270
AIを活用したE2Eテスト実装効率化のあゆみ / ebisu-mobile-14-kotetu
kotetuco
0
150
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
430
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
7k
Agentic UI
manfredsteyer
PRO
0
210
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
260
Featured
See All Featured
First, design no harm
axbom
PRO
2
1.2k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
GitHub's CSS Performance
jonrohan
1033
470k
Prompt Engineering for Job Search
mfonobong
0
360
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
630
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
610
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
630
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
160
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2k
Chasing Engaging Ingredients in Design
codingconduct
0
230
Mobile First: as difficult as doing things right
swwweet
225
10k
Transcript
Stimulusのすすめ Railsエンジニアのサイドスキルとしてのフロントエンド開発 2025.07.25 Sendai.rb #43 #sendairb あのぶる 𝕏: @thatblue_plus :
@thatblue.bsky.social
JS、どのくらい書いてますか?
「RubyとRails(+SQL)だけ分かってればOK」みたいな 現場は実はあんまり多くない気がする(個人の感想です) • 例1・Webアプリケーション開発の現場: チームにフロントエンドがメインの エンジニアも居るが、そこそこフロントも触らないといけない ◦ もしくは、フロントエンドと完全に二足のわらじ • 例2・スマホアプリ開発の現場:
サービス側のフロントはネイティブアプリな ので完全にノータッチだが、バックオフィスツールの開発がバックエンド (Rails)チームの業務になっている • 例3・社内システム開発の現場など: あんまりフロントをリッチに作る要件が なく、フロント専任のメンバーをアサインする程の必要性がない
「RubyとRails(+SQL)だけ分かってればOK」みたいな 現場は実はあんまり多くない気がする(個人の感想です) • 例1・Webアプリケーション開発の現場: チームにフロントエンドがメインの エンジニアも居るが、そこそこフロントも触らないといけない ◦ もしくは、フロントエンドと完全に二足のわらじ • 例2・スマホアプリ開発の現場:
サービス側のフロントはネイティブアプリな ので完全にノータッチだが、バックオフィスツールの開発がバックエンド (Rails)チームの業務になっている • 例3・社内システム開発の現場など: あんまりフロントをリッチに作る要件が なく、フロント専任のメンバーをアサインする程の必要性がない 今回のターゲットは主にここ
必要になったとして、いまどきのJSフレームワークを がっつり使うほどではないことが多い
そこで「控えめなJavaScriptフレームワーク」であるStimulusのすすめ ※the 上司の受け売り Railsがなくても使えます
Rails7からデフォルトになった、Hotwireのコンポーネントのひとつ • Turbo ◦ Turbo Native • Stimulus • (Strada?)
Stimulusとは?
「Stimulus=刺激」の名のとおり、何かしらの画面操作を起点とした処理(だいた いイベント処理に相当)を宣言的に記述するためのJSフレームワーク ⇒「猫でもわかるHotwire入門 Turbo編」によると、「カオスになりがちな JavaScriptのコードにレールを敷く役割を担っている」とのこと Stimulusとは?
ドキュメントトップページのJSを再現
HTML部分 <div data-controller="hello"> <input data-hello-target="name" type="text" placeholder="your name"> <button data-action="click->hello#greet">Greet</button>
<div data-hello-target="output" id="hello-target"></div> </div>
Stimulusのコード import { Application, Controller } from "https://unpkg.com/@hotwired/stimulus/dist/stimulus.js" window.Stimulus =
Application.start() Stimulus.register("hello", class extends Controller { static targets = ["name", "output"] greet() { this.outputTarget.textContent = `Hello, ${this.nameTarget.value}!` } }) targetの中身は普通に HTMLElement
いや、これでよくね?🤔 const greetButton = document.getElementById("greet") greetButton.addEventListener("click", () => { const
name = document.getElementById("name") const outputTarget = document.getElementById("hello-target") outputTarget.textContent = `Hello, ${name.value}!` })
それはそう…ではあるんだけど • HTML(≒ビューファイル)側が主導権を持っている ◦ viewファイルを見ればどこにJSの処理が組み込まれているかが分かるのはRails主体のアプリ ケーションとしては便利 ◦ 「8割がたの機能はサーバサイドで完結するが、ちょっとした便利な操作をJSで実装したい」 というケースに向いている(都道府県選択⇒市町村のプルダウン生成、など) ◦
例えば「2010年代にjQueryベースで書かれたコードをいい加減モダンにしたいんだけど」と いう需要には実際ピッタリだと思う • がっつりビルドプロセスを組まなくてもCDNで読み込めば動く • 「控えめ」であるがゆえにTurboとも組み合わせやすい ◦ ついでにRequest.JS for Railsと組み合わせると画面操作をトリガーにして非同期で検索結果 を画面に反映させる、なんて処理もわりと簡単に実装できます Rails側でビューを管理できて便利
ライフサイクルコールバックもある
ついでに 「カルーセルメニュー」「アコーディオン」「ダイアログ」「ドラッグ&ドロッ プによる並べ替え」など、よくある機能がパッケージとして用意されている https://www.stimulus-components.com/
TypeScriptとはちょっと相性が悪い(らしい)かも…? export default class MyController extends Controller { static values
= { code: String // ここの型定義はTSは認識しない } declare codeValue: string // 二重に定義する手間がある declare readonly hasCodeValue: boolean }
参考資料 • Stimulus 公式ドキュメント ◦ https://stimulus.hotwired.dev/ • 猫でもわかるHotwire入門 Turbo編 ◦
https://zenn.dev/shita1112/books/cat-hotwire-turbo