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
Yet another side effect layer for Redux
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Daisuke Mino
April 24, 2018
Programming
2.8k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Yet another side effect layer for Redux
Daisuke Mino
April 24, 2018
More Decks by Daisuke Mino
See All by Daisuke Mino
複雑なコンポーネントで 状態をもつのをやめた話
minodisk
0
140
io.Writerで学ぶGoのインターフェース
minodisk
0
250
Goのエラーハンドリング
minodisk
0
210
Other Decks in Programming
See All in Programming
Inside Stream API
skrb
1
700
dRuby over BLE
makicamel
2
330
Composerを使ったサプライチェーン攻撃の様子を眺めてみる #phpstudy
o0h
PRO
2
250
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.2k
Lessons from Spec-Driven Development
simas
PRO
0
190
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
10
4k
AIだと陥りがちなJakarta EE最新技術への移行時の落とし穴と解決策
tnagao7
0
110
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
190
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
170
JavaDoc 再入門
nagise
0
330
Contextとはなにか
chiroruxx
1
310
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
580
Featured
See All Featured
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
380
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
Code Reviewing Like a Champion
maltzj
528
40k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Fireside Chat
paigeccino
42
3.9k
Facilitating Awesome Meetings
lara
57
7k
How to Talk to Developers About Accessibility
jct
2
230
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
The Spectacular Lies of Maps
axbom
PRO
1
800
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.1k
Scaling GitHub
holman
464
140k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
270
Transcript
Yet another side effect layer for Redux Scramble! #1 @minodisk
Redux͕Δ͜ͱ άϩʔόϧεςʔτΛҡ࣋͢ΔͨΊͷ࣮ • Connector • Dispatcher • Reducer • Store
Redux͕Βͳ͍͜ͱ ෭࡞༻ͷ͋ΔॲཧΛॻ͘ॴͷఏڙ • APIτϥοΩϯά༻ϝιουͷίʔϧ • Local StorageCookieͷΞΫηε • ReactΞϓϦέʔγϣϯ֎ͷDOMૢ࡞
Ͳ͜ͰΔ͔ʁ େ͖͚͘Δͱ͜Μͳൊ͕͋Γͦ͏ • ComponentͰΔ • ActionൃߦલʹΔ redux-thunk • ActionൃߦޙɺReduceલʹΔ redux-saga
Ͳ͜ͰΔ͔ʁ • ComponentͰΔͷ֎ • redux-thunkActionΛDispatch͢Δͷ͔ Action DispatcherΛDispatch͢Δͷ͔౷Ұײ͕ ͳ͍ίʔυʹͳͬͯ͠·͏ • redux-sagaผϨΠϠʔͰΔͷͰɺ
֤ϨΠϠʔ͕ͦΕͧΕͷʹूதͰ͖Δ
redux-sagaͷΑ͞ • ֤ϨΠϠʔ͕ࣗͷʹूதͰ͖Δ • ViewActionΛൃߦ͢Δ͚ͩ • ෭࡞༻ϨΠϠʔͰActionΛड͚औΓɺ ActionΛൃߦ͢Δ͚ͩ • ActionͷTypeΛϑοΫͯ͠ॲཧΛࣗ༝ʹॻ͚Δ
redux-sagaͷͭΒΈ • Generatorਏ͍ • ςετਏ͍ • Effectsؔਏ͍
ສೳނͷਏΈ • GeneratorͳΒશͯͷ͜ͱ͕Ͱ͖Δ͔͠Εͳ ͍ • ݱ࣮ʹҰൠతͳWebΞϓϦέʔγϣϯͰॻ͘ ॲཧͷ99%Async/Await/Promise.allͰͬ ͍͚ͯΔ୯७ͳίʔυ • 1%ΛຒΊΔͨΊʹෳࡶੑ͕ۃ·ͬͯΔ
Զୡ͕ཉ͔ͬͨ͠ͷ
Image by www.projectcartoon.com / CC BY 3.0
࡞ͬͨ
redux-spork
Spork is Կ?
Spoon x Fork Image by Wtshymanski at English Wikipedia /
CC BY-SA 3.0
Specifications • action.typeΛΩʔʹcallbackΛొ͢Δ • callbackͨͩͷfunctionͰɺasyncʹͰ͖Δ • callbackʹ͞ΕΔdispatchϝιουͰผactionΛൃߦ • ൃߦ͞Εͨaction࠶ϑοΫ͞Εcallback͕ݺΕΔ •
1-action:N-callback, N-action:1-callback
Fork
Component Reducer Action
Component Reducer Fork Action
Component Reducer Fork Action Action Dispatch
Component Reducer Fork Action Action Dispatch Action
Component Reducer Fork Action Action Dispatch Fork
Component Reducer Fork Action Action Dispatch
Component Reducer Fork Action Action Dispatch
Component Reducer ORDER USER_FETCH USER_FETCHED
Merge
Component Reducer ORDER Merge USER_FETCH USER_FETCHED
͜Μͳ͔Μ͡ 1 fork('ORDER', async (action, dispatch) => {¬ 2 dispatch({
type: 'USER_FETCH', action.payload.userID })¬ 3 const { payload } = await merge('USER_FETCHED')¬ 4 const resp = await fetch(`/api/orders`, {¬ 5 method: 'POST',¬ 6 body: JSON.stringify({ productID: action.payload.productID }),¬ 7 })¬ 8 dispatch({ type: 'ORDERED', payload: JSON.parse(resp.body) })¬ 9 })
ͱ͜ΖͰ
redux-observable ʹࢥ͕ࣅͯΔΑͶʁ
Spork Image by Wtshymanski at English Wikipedia / CC BY-SA
3.0
Observable Image by Dave Taylor at Flickr / CC BY
2.0
·ͱΊ • ϨΠϠʔ͕Γ͚ΒΕΔ • ͷ • γϯϓϧ • Async/AwaitͰ͍͖ͬͯ
Repository • https://github.com/folio-sec/redux-spork • https://www.npmjs.com/package/redux- spork
͝ਗ਼ௌ͍͖ͨͩ ͋Γ͕ͱ͏͍͟͝·ͨ͠