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
560
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
80
Vue/Nuxt tutorial for Sendai
masuidrive
0
230
ハッカソンで 作ったアプリを売却した話
masuidrive
0
750
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
Acquisition / Takeover
bvr7352
0
110
EL GEOPARQUE MUNDIAL UNESCO VOLCANES DE CALATRAVA: DE LA INVESTIGACIÓN CIENTÍFICA A LA TRANSPOSICIÓN DIDÁCTICA EN EL AULA
juanmartin2026
0
53k
Sanapilvet opetuksessa
matleenalaakso
1
36k
Requirements Analysis and Prototyping - Lecture 3 - Human-Computer Interaction (1023841ANR)
signer
PRO
0
1.9k
Another One Writes the Code
minecr
0
120
Sekolah Sabat - Triwulan 4 2026 - Pelajaran 2
hiola
0
11k
Padlet opetuksessa
matleenalaakso
12
16k
Merger Process
bvr7352
0
180
Before You Scale: Understand the Theory Behind the Simulation
pfn
PRO
1
160
Human Perception and Cognition - Lecture 4 - Human-Computer Interaction (1023841ANR)
signer
PRO
0
1.7k
GENERAL PHARMACOLOGY
pawan_pharm
0
230
BRIEF OUTLINE OF IMPORTANT PLANT CONSTITUENTS
pawan_pharm
0
240
Featured
See All Featured
Designing Powerful Visuals for Engaging Learning
tmiket
1
620
The browser strikes back
jonoalderson
0
1.9k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
270
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
How STYLIGHT went responsive
nonsquared
100
6.3k
Practical Orchestrator
shlominoach
192
12k
Utilizing Notion as your number one productivity tool
mfonobong
4
630
Rails Girls Zürich Keynote
gr2m
96
14k
RailsConf 2023
tenderlove
30
1.6k
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