Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Rails loves React
Search
Yuichiro MASUI
December 31, 2017
Education
550
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rails loves React
Yuichiro MASUI
December 31, 2017
More Decks by Yuichiro MASUI
See All by Yuichiro MASUI
Coding Agent用チケットシステム - ticket.sh
masuidrive
0
68
Vue/Nuxt tutorial for Sendai
masuidrive
0
230
ハッカソンで 作ったアプリを売却した話
masuidrive
0
720
DJ hands on for IT Engineers
masuidrive
1
220
自分の棚卸をして レジュメを書こう
masuidrive
5
2.1k
0から1ヶ月で DJになるまで
masuidrive
4
1.7k
Google Apps Scriptでbotを作る話
masuidrive
1
1.8k
トレタの存在理由
masuidrive
0
260
18年でRubyから学んだこと - 関西Ruby会議 2017
masuidrive
3
2.3k
Other Decks in Education
See All in Education
sepm-training-sample
levii
0
230
ちいかわを読め
uchi8977
1
340
Soluciones al examen de Geografía 2026. JUNIO (Convocatoria Ordinaria)
juanmartin2026
1
10k
マークシート試験のTeX言語を用いた自動採点について
doratex
0
3.4k
One Year of Learning English with AI @エンジニア英語キャリア Meetup #3
kekekenta
0
220
Stardy 会社紹介資料
stardy
0
7.9k
2026年度春学期 統計学 第11回 分布の「型」を考える - 確率分布モデルと正規分布 (2026. 6. 11)
akiraasano
PRO
0
180
25-26 CBT Library top items
cbtlibrary
0
260
2026年度春学期 統計学 第15回 分布についての仮説を検証する ― 仮説検定(2) (2026. 7. 9)
akiraasano
PRO
0
130
【新規入学者様】ZEPメタバース校舎ガイド
ainischool
0
140
Examen de Selectividad. Geografía junio 2026 (Convocatoria Ordinaria). UCLM
juanmartin2026
1
6.6k
【デザイナー就活講座】 デザイナー就活市場・企業探し・ポートフォリオのポイント
koheihasebe
0
590
Featured
See All Featured
Documentation Writing (for coders)
carmenintech
77
5.5k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Statistics for Hackers
jakevdp
799
230k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Bash Introduction
62gerente
615
220k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
280
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6.2k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
480
sira's awesome portfolio website redesign presentation
elsirapls
0
410
RailsConf 2023
tenderlove
30
1.5k
Transcript
Rails ♥ React Yuichiro MASUI / Toreta, Inc.
@masuidrive ૿Ҫ ༤Ұ
What’s React • FacebookJavascriptͷViewΤϯδϯ • TwitterAbema.tv ͳͲେنʹΘΕͯΔ • ߏతʹαʔόαΠυ͖ •
ϥΠηϯεͰᎍΊ͚ͨͲMITͰམ͍ͪͭͨ
ΫϥΠΞϯτϩδοΫ αʔόαΠυੜ ϒϥβ ϩδοΫ (ίϯτϩʔϥ) ϦΫΤετ αʔό ΫϥΠΞϯτ Πϕϯτ (onSubmit)
React αʔόϩδοΫ HTMLੜ෦ (render) HTMLੜ෦ (ςϯϓϨʔτ) ը໘Λදࣔ͢ΔͨΊͷঢ়ଶ (setState) ը໘Λදࣔ͢ΔͨΊͷঢ়ଶ (ςϯϓϨʔτม)
ͳͥReactΛ͏ͷ͔ • jQuery͏Ί͍ͨ • ϖʔδͰͷঢ়ଶͷมԽ͕ଟ͍ • WebSocketWebRTCͷΑ͏ͳ௨৴Λ͏ • Semantic-UIMaterial-UIͷΑ͏ͳϦονͳUIΛ͍͍ͨ
Rails + Rails • Webpacker + React (Rails 5.1͔Β •
react-rails (React७ਖ਼ Rails࿈ܞ • react_on_rails
Webpacker • Rails 5.1͔Βಋೖ͞Εͨ Webpack ͷϥούʔ • JavascriptCSSͷϏϧυπʔϧ • ΊͪΌͪ͘Ό໘
• ෦ͰBabelnode-sassΛݺͼग़͍ͯ͠Δ
Browserify • ϞμϯͳJavascriptΛϒϥβͰಈ͘Α͏ʹม • ίϯύΠϥͳͲ֎෦Λݺͼग़͢ • ҰͭͷϑΝΠϧ͚ͩϏϧυ͢ΔͳΒWebpackΑΓָ
None
Parcel bundler • ࠓேQiitaͰݟͯࢼͯ͠Έͨ • ιʔεΛݟͯґଘؔΛղੳͯ͠Ϗϧυ͢Δπʔϧ • ͜͏ͬͯ࣍ʑ৽͍͠πʔϧ͕ग़ͯ͘Δ
ڥΛ”ࠞͥΔͳةݥ” • ։ൃɾϦϦʔελΠϛϯάͷҧ͍ • ݴޠɾڥͷҧ͍ • ϥούʔେΊΜͲ͍͘͞
Nodeͷڥผʹ࡞Ζ͏ • DockerΛͬͯɺRailsͷڥͱReactͷڥΛ͚Δ • Ϗϧυڥผʹཧ • ࿈ಈͯ͠Ϗϧυ͢ΔΈͲ͏͢Δʁ
Dockerfile FROM ruby:2.4 ENV LANG C.UTF-8 RUN apt-get update &&
\ apt-get install -y nodejs mysql-client --no-install-recommends && \ rm -rf /var/lib/apt/lists/* && \ mkdir -p /usr/src/app WORKDIR /usr/src/app COPY Gemfile /usr/src/app/ COPY Gemfile.lock /usr/src/app/ RUN bundle install COPY . /usr/src/app EXPOSE 3000 CMD ["./bin/rails", "server", "-b", "0.0.0.0"]
react/Dockerfile FROM node:8 WORKDIR /usr/src/app ADD package.json /usr/src/app/package.json RUN yarn
install COPY . /usr/src/app
docker-compose.yml rails: build: . command: [ "bash", "-c", "rm -f
tmp/pids/server.pid; ./bin/rails server -b 0.0.0.0" ] environment: DISABLE_SPRING: "1" ports: - "3000:3000" volumes: - ".:/usr/src/app" links: - “mysql" react: build: react volumes: - "./react/src:/usr/src/app/src" - "./app/assets/javascripts:/usr/src/app/dist" - "node_modules" command: [ "yarn", "run", "watch" ] mysql: image: mysql:5.6 environment: MYSQL_ROOT_PASSWORD: "passwd"
σΟϨΫτϦߏ • root - ී௨ͷRails project • react - React෦ͷιʔεͱڥ
• app/javascripts - Ϗϧυ͞ΕͨReactίʔυ
ReactͷϏϧυ • browserifyΛ͏ browserify src/index.jsx -o dist/index -t [ babelify
-- presets [ es2015 react ] ] • Parcel bundlerΛ͏ parcel src/index.jsx • watchͰࢹ watch -p "src/**/*.js*" -c "yarn run build”
Pros / Cons • Pros • ಛผͳ࿈ܞϞδϡʔϧͳͲΛ༻͍ͳ͍ • Webpack͕ඞཁͳ͍ •
Cons • Dockerڥ͕ඞཁ • Ϗϧυ࣌ʹRailsͱ࿈ಈ͠ͳ͍
τϨλͷReact • ૿Ҫ͕ॻ͍͍ͯΔ͚ࣾπʔϧ͚ͩ • WebRTCWebSocketͬͨπʔϧ • Single Page ApplicationͰͳ͍
View͔Βͷݺͼํ • ը໘ຖʹಡΈࠐΉJavascriptΛͲ͏ܾఆ͢Δ͔ • ύϥϝʔλΛͲ͏ͬͯReactʹ͔͢
None
None
Form͚ͩReact
Α͋͘ΔϢʔβొ • ໊લɺϝΞυɺύεϫʔυ • validateͰ͖ͨΒSubmit͕ԡͤΔΑ͏ʹ • ௨৴ී௨ͷForm submit
None
None
None
None
XHR/fetch͠ͳͯ͘ React͏ͱศར
ͬͱෳࡶͳΒ
Redux • ReactͱڞʹΘΕΔϑϨʔϜϫʔΫ • ঢ়ଶΛมߋ͢ΔʹActionΛൃߦͯ͠ɺReducerͰStoreΛ มߋ͢Δ͔͠ͳ͍ • શͯͷঢ়ଶStoreʹอଘ͞ΕΔ
Hot load • Reactͷେ͖ͳಛ • ϒϥβΛϦϩʔυͤͣʹঢ়ଶΛͨ͠··DOMͷมߋ ͤ͞Δ • Reactͷঢ়ଶɺstateͱpropsʹೖ͍ͬͯΔͷͰɺ͜ΕΛ อ࣋ͨ͠··ΦϒδΣΫτπϦʔΛ࠶ߏங͢Δ
• ιʔείʔυͷมߋ௨WebSocketͰߦ͏
࠷ۙݟ͚ͭͨ ศརͳϥΠϒϥϦ
None