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
Async in Redux
Search
Darpan Kakadia
October 25, 2017
Technology
0
260
Async in Redux
Slides from my talk at ReactiveConf 2017 on how to handle Async in Redux.
Darpan Kakadia
October 25, 2017
Tweet
Share
Other Decks in Technology
See All in Technology
mrubyと micro-ROSが繋ぐロボットの世界
kishima
2
340
“社内”だけで完結していた私が、AWS Community Builder になるまで
nagisa53
1
400
Witchcraft for Memory
pocke
1
460
生成AIで小説を書くためにプロンプトの制約や原則について学ぶ / prompt-engineering-for-ai-fiction
nwiizo
4
2.4k
250627 関西Ruby会議08 前夜祭 RejectKaigi「DJ on Ruby Ver.0.1」
msykd
PRO
2
320
ひとり情シスなCTOがLLMと始めるオペレーション最適化 / CTO's LLM-Powered Ops
yamitzky
0
440
登壇ネタの見つけ方 / How to find talk topics
pinkumohikan
5
530
A2Aのクライアントを自作する
rynsuke
1
200
Node-REDのFunctionノードでMCPサーバーの実装を試してみた / Node-RED × MCP 勉強会 vol.1
you
PRO
0
120
CI/CD/IaC 久々に0から環境を作ったらこうなりました
kaz29
1
190
AWS Summit Japan 2025 Community Stage - App workflow automation by AWS Step Functions
matsuihidetoshi
1
290
OpenHands🤲にContributeしてみた
kotauchisunsun
1
470
Featured
See All Featured
It's Worth the Effort
3n
185
28k
[RailsConf 2023] Rails as a piece of cake
palkan
55
5.6k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
5.9k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
Designing for Performance
lara
609
69k
How STYLIGHT went responsive
nonsquared
100
5.6k
Art, The Web, and Tiny UX
lynnandtonic
299
21k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
138
34k
Why You Should Never Use an ORM
jnunemaker
PRO
58
9.4k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.5k
We Have a Design System, Now What?
morganepeng
53
7.7k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
Transcript
Async in Redux
Darpan Kakadia UI Engineer @Cleartrip @kakadiadarpan
Promises, Thunks or Sagas?
You need just one!
You need just one!
Redux saga is a library which helps you manage async
actions using ES6 generator functions. Redux Saga
import { delay } from 'redux-saga' import { put, takeEvery
} from 'redux-saga/effects' // Our worker Saga: will perform the async increment task export function* incrementAsync() { yield delay(1000) yield put({ type: 'INCREMENT' }) } // Our watcher Saga: spawn a new incrementAsync task on each INCREMENT_ASYNC export function* watchIncrementAsync() { yield takeEvery('INCREMENT_ASYNC', incrementAsync) }
import { delay } from 'redux-saga' import { put, takeEvery
} from 'redux-saga/effects' // Our worker Saga: will perform the async increment task export function* incrementAsync() { yield delay(1000) yield put({ type: 'INCREMENT' }) } // Our watcher Saga: spawn a new incrementAsync task on each INCREMENT_ASYNC export function* watchIncrementAsync() { yield takeEvery('INCREMENT_ASYNC', incrementAsync) }
import { delay } from 'redux-saga' import { put, takeEvery
} from 'redux-saga/effects' // Our worker Saga: will perform the async increment task export function* incrementAsync() { yield delay(1000) yield put({ type: 'INCREMENT' }) } // Our watcher Saga: spawn a new incrementAsync task on each INCREMENT_ASYNC export function* watchIncrementAsync() { yield takeEvery('INCREMENT_ASYNC', incrementAsync) }
Let’s see how Thunks compares with Saga?
function fetchData() { return dispatch => { axios .get("/data") .then(data
=> {dispatch({ type: "FETCH_SUCCESS", data });}) .catch(error => dispatch({ type: "FETCH_FAILED", error })); }; } Redux Thunk
function fetchData() { return dispatch => { axios .get("/data") .then(data
=> {dispatch({ type: "FETCH_SUCCESS", data });}) .catch(error => dispatch({ type: "FETCH_FAILED", error })); }; } Redux Thunk
function fetchData() { return dispatch => { axios .get("/data") .then(data
=> {dispatch({ type: "FETCH_SUCCESS", data });}) .catch(error => dispatch({ type: "FETCH_FAILED", error })); }; } Redux Thunk
function* fetchData() { try { const data = yield call(axios.get,
"/data"); yield put({ type: "FETCH_SUCCESS", data }); } catch (error) { yield put({ type: "FETCH_FAILED", error }); } } function* rootSaga() { yield* takeLatest("FETCH_DATA", fetchData); } Redux Saga
function* fetchData() { try { const data = yield call(axios.get,
"/data"); yield put({ type: "FETCH_SUCCESS", data }); } catch (error) { yield put({ type: "FETCH_FAILED", error }); } } function* rootSaga() { yield* takeLatest("FETCH_DATA", fetchData); } Redux Saga
function* fetchData() { try { const data = yield call(axios.get,
"/data"); yield put({ type: "FETCH_SUCCESS", data }); } catch (error) { yield put({ type: "FETCH_FAILED", error }); } } function* rootSaga() { yield* takeLatest("FETCH_DATA", fetchData); } Redux Saga
function* fetchData() { try { const data = yield call(axios.get,
"/data"); yield put({ type: "FETCH_SUCCESS", data }); } catch (error) { yield put({ type: "FETCH_FAILED", error }); } } function* rootSaga() { yield* takeLatest("FETCH_DATA", fetchData); } Redux Saga
Isn’t that just too much work?
Advantages of redux-saga
• Task cancellation Advantages of redux-saga
• Task cancellation • Race conditions Advantages of redux-saga
• Task cancellation • Race conditions • Throttling Advantages of
redux-saga
• Task cancellation • Race conditions • Throttling • Debouncing
Advantages of redux-saga
• Task cancellation • Race conditions • Throttling • Debouncing
• Retrying network calls Advantages of redux-saga
• Task cancellation • Race conditions • Throttling • Debouncing
• Retrying network calls • Undo actions Advantages of redux-saga
@kakadiadarpan