Please enable JavaScript.
Coggle requires JavaScript to display documents.
Redux Saga - Coggle Diagram
Redux Saga
Methods
-
-
yield call
{ CALL: {fn: delay, args: [1000]}}
-
yield apply
yield apply(obj, obj.method, [arg1, arg2, ...])
-
-
yield takeLatest
Does not allow concurrent fetches of user. If fetch is already pending, that pending fetch is cancelled and only the latest one will be run
-
-
HOW
To run our Saga, we'll have to connect it to the Redux Store using the redux-saga middleware.
If the browser you are targeting doesn't support ES2015 generators, you must transpile them
We'll create a Saga that watches for all USER_FETCH_REQUESTED actions and triggers an API call to fetch the user data.
-
-
-
-
-
Why
this thread can be started, paused and cancelled from the main application with normal redux actions, it has access to the full redux application state and it can dispatch redux actions as well.
-
-
-
-
Contrary to redux thunk, you don't end up in callback hell,
make application side effects (i.e. asynchronous things like data fetching and impure things like accessing the browser cache)
Error Handling
Errors in forked tasks bubble up to their parents until it is caught or reaches the root saga. If an error propagates to the root saga the whole saga tree is already terminated.
The preferred approach, in this case, to use onError hook to report an exception, inform a user about the problem and gracefully terminate your app.
-
-
-