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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
220
Other Decks in Programming
See All in Programming
変わらないものが、変わるものを決める — 意図駆動開発 × イベントソーシング × イミュータブル | What Doesn't Change Decides What Can — IDD × Event Sourcing × Immutability
tomohisa
0
1.8k
PHP Application における Kubernetes 内 gRPC 通信
ganchiku
0
600
夏だ!祭りだ!祭りとはドメインモデリングでは?
ryugen04
0
330
いまどきの Codex で開発する visionOS アプリの開発スタイルについて
karad
0
150
freeeにおけるEvalsの実践例の紹介
freee
PRO
0
130
仕様駆動開発へのトライを機に チームに適合する手法を模索し続けている話
freee
PRO
0
580
AIを紡ぐPMのお話
swdtkuy
0
120
S3 を使うアプリケーションをローカル完結で動かすことに全力を注いでみた / Running S3 Apps Offline
contour_gara
0
550
リアルな遅延を測る仕様
kota_yata
1
120
生成AIで帳票OCRが「簡単に」作れる時代になった?
kon_shou
0
1.1k
What's New in Android 2026
veronikapj
0
270
AIが無かった頃の素敵な出会いの話
codmoninc
1
480
Featured
See All Featured
Paper Plane
katiecoart
PRO
2
53k
Making Projects Easy
brettharned
120
6.7k
Music & Morning Musume
bryan
47
7.3k
Site-Speed That Sticks
csswizardry
13
1.5k
It's Worth the Effort
3n
188
29k
The Pragmatic Product Professional
lauravandoore
37
7.4k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
400
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
950
Typedesign – Prime Four
hannesfritz
42
3.1k
Facilitating Awesome Meetings
lara
57
7.1k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
490
New Earth Scene 8
popppiees
3
2.5k
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
͝ਗ਼ௌ͍͖ͨͩ ͋Γ͕ͱ͏͍͟͝·ͨ͠