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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
分散システム、なんですぐ死んでしまうん?耐障害性を高めたいあなたのためのレジリエンスパターン入門
mshibuya
7
5.8k
SREは、MCPとSRE Agentをこう使え!
kazumax55
0
150
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
520
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
0
160
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
260
OSINT for SRE: 学術論文とポストモーテムから探る システム障害の共通パターン / SRE NEXT 2026
tomoyk
1
3.6k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
140
Vite+ Unified Toolchain for the Web
naokihaba
0
750
どこまでゆるくて許されるのか
tk3fftk
0
480
SLOをサービス品質の共通言語にするために 取り組んできたこと
wakana0222
0
490
The Bowling Game- From Imperative to Functional Programming - Part 1
philipschwarz
PRO
0
320
技術記事、 専門家としてのプログラマ、 言語化
mizchi
14
7.4k
Featured
See All Featured
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
190
So, you think you're a good person
axbom
PRO
2
2.1k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
940
Raft: Consensus for Rubyists
vanstee
141
7.6k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
Ruling the World: When Life Gets Gamed
codingconduct
0
280
Docker and Python
trallard
47
3.9k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
WCS-LA-2024
lcolladotor
0
690
Technical Leadership for Architectural Decision Making
baasie
3
440
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
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
͝ਗ਼ௌ͍͖ͨͩ ͋Γ͕ͱ͏͍͟͝·ͨ͠