Redux Async - Course Introduction: Let Us First Try To Understand The Asynchronous Behaviour!
Redux Async - Course Introduction: Let Us First Try To Understand The Asynchronous Behaviour!
Asynchronicity Explained
Each of these details are served by different API's and time taken to return the results can be
different. Making asynchronous calls to each of these APIs allow displaying the details on
the page without waiting for all the calls to get completed.
Asynchronicity Decoded!
Did you note something different in our Example Application?
The final data chunks took time before being available to user! The asynchronicity that arises
after submitting data is handled by Redux in an excellant manner.
Please note that dispatch of the action CANCEL_FETCH is delayed by 2000 ms/ 2sec. Thus,
making it possible to control when and how the developer can dispatch the action.
For example:
{ type: 'GET_REQUEST' }
{ type: 'GET_REQUEST_FAIL', error: 'Request failed' }
{ type: 'GET_REQUEST_SUCCESS', response: { ... } }
Examine the Pen https://codepen.io/anon/pen/OmRRQJ for the complete code for the first
Redux app with asynchronous action.
document.getElementById('delayedHello').addEventListener('click', function () {
setTimeout(function () {
store.dispatch({ type: 'DELAYED_HELLO' })
}, 3000)
})
Here you can notice that the action is dispatched with a delay of 3 seconds, thus making it
asynchronous.
Use Codepen Playground
Middleware in Redux
The examples covered so far in the Redux State Management course, have
implemented synchronous actions, that returned the new state, but did not 'modify' the global
state.
What is Middleware?
Middleware can be seen as software gums that make software development easy, by
composing functionalities. Middleware functions enable developers to design action
creators which return another function.
Redux Thunk
The name "Thunk" is inspired from the word think!
Installing Thunk
Before exploring middleware , we need to install the package redux-thunk and enable
in store.
For Installing:
Here:
Custom arguments
Custom argument in thunk can be injected using "withExtraArgument" function.
This pen covers the basics that we learnt during the course.
Key Highlights:
Fork the pens shared through out the course and try to improve the applications for a better
understanding of the concepts you have gone through in this course.
Quiz:
1. Redux middleware is responsible for mainly handling __ asynchornus
2. General action creators are function which return__ an action
3. Redux thunk is used to make__ asynchornous API
4. Middleware is basically__ Both
5. Based on the hands on card “MLR Hands On” What is the P>|t| value for the 'INDUS' variable ? 0,731
6. When an asynchronous API is called, it requires a change in the state of application. T
7. What is “setTimeout” method used for? CALL A FUNC
8. Based on the hands on card “MLR Hands On” What is the value of the estimated coef for the constant
term ? 36,4
9. Based on the hands on card “MLR Hands On” Perform a correlation among all the independent
variables . What is the correlation between variables NOX and DIS ? 0,769
10. Middleware is__ BOTH
11. Asynchronous actions can define BOTH
12. Middleware are responsible for making API calls T
13. Action creators which have asynchronous behaviour dispatch actions__ AFTER THEY RECEIVE A RESULT
14. Based on the hands on card “MLR Hands On” What is the standard error for the constant term ? 5,104
15. When an asynchronous API is called, it requires a change in the state of application. T
16. Based on the hands on card “MLR Hands On” what is the value of R sq ? 0,741
17. Once the Redux Thunk middleware is enabled WE CAN....
18. What is Thunk? ALL
19. While making an API call, which of these is preferred? USE MULTIPLE
20. For an API request, which of the following action is dispatched first? REQUEST BEGAN
21. import { createStore, applyMiddleware } from 'redux'; is used for__ ENABLEING
22. Thunk installation is done with following command : NPM-INSTALL
23. For more complex asynchronous actions, which of the following would work?: ALL
24. Once the Redux Thunk middleware is enabled WE CAN....
25. Thunk middleware is the only way to implement asynchronous actions in Redux! F
26. Redux promise middleware is used to__ to dispatch Promises
27. To dispatch promise-based asynchronous actions, which of the following can be used? redux-pack
28. Redux-observable can be used to dispatch observable
29. Custom argument in thunk can be injected using with extra argument
30. Redux thunk is used to make- Asynchronous API calls
31. Only functions can be dispatched in asynchronous middleware. F
32. Middleware is basically__ High Order
33. Asynchronicity is all about "
34. occurrence of phenomena at the same time"
35. For more complex asynchronous actions, which of the following would work?: Saga