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
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
Throw Yourself In! - How I've learned English and What I'm Facing
georgeorge
1
260
Carbohydrates: Classification, Structure & Chemical Properties
pawan5505
0
210
[2026前期火5] 論理学(京都大学文学部 前期 第12回)「証明を走らせる:カリー・ハワード対応」
yatabe
0
300
25-26 CBT Library top items
cbtlibrary
0
210
Sekolah Sabat - Triwulan 3 2026 - Pelajaran 12
hiola
0
2k
Del ojo entrenado a la visión computacional: evaluación de la severidad de enfermedades
emdelponte
0
120
Leveraging LLMs for student feedback in introductory data science courses
minecr
0
110
中小規模私大の教学IRを支えるデータマネジメント ― データ基盤構築の取り組みと実務の現在地 ―
terazawa
0
110
AIの力を100%引き出すために
frievea
0
500
[2026前期火5] 論理学(京都大学文学部 前期 第14回)「計算は、証明ではない——ハルシネーションを三層ハーモニーで診る」
yatabe
0
250
One Year of Learning English with AI @エンジニア英語キャリア Meetup #3
kekekenta
0
190
Stardy 会社紹介資料
stardy
0
7.4k
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
For a Future-Friendly Web
brad_frost
183
10k
Ethics towards AI in product and experience design
skipperchong
2
360
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
280
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
660
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Chasing Engaging Ingredients in Design
codingconduct
0
300
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
680
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
260
How to Ace a Technical Interview
jacobian
281
24k
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