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
79
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
Another One Writes the Code
minecr
0
110
【ainiチャット】2段階認証設定方法
ainischool
0
120
パラグラフから始めるアカデミック・ライティング
neuroiwm
3
2.5k
人工知能とは/IntroAI02
kfujita
0
110
生成AIとの付き合い方/ How to work with AI
kaityo256
PRO
3
920
The Dirty Dozen: 12 gala mistakes you don’t know you’re making
auctria
PRO
0
220
Introduction - Lecture 1 - Web Technologies (1019888BNR)
signer
PRO
0
6.6k
Introduction to Primary and Secondary Metabolites their Metabolic Pathways
drpoonamkc
0
180
【ainiチャット操作ガイド】
ainischool
0
160
DRUGS ACTING ON THE PERIPHERAL NERVOUS SYSTEM
pawan_pharm
0
200
Sekolah Sabat - Triwulan 4 2026 - Pelajaran 5
hiola
0
1.6k
LEGO Geometry Tutorial
arnoknobbe
0
750
Featured
See All Featured
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
720
The Spectacular Lies of Maps
axbom
PRO
1
1.1k
Ruling the World: When Life Gets Gamed
codingconduct
0
420
Product Roadmaps are Hard
iamctodd
55
13k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
460
How STYLIGHT went responsive
nonsquared
100
6.3k
A Modern Web Designer's Workflow
chriscoyier
699
190k
Testing 201, or: Great Expectations
jmmastey
46
8.4k
Design in an AI World
tapps
1
360
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
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