D
D
DiMoNTD2016-09-18 11:23:33
JavaScript
DiMoNTD, 2016-09-18 11:23:33

What is the correct approach to implement asynchronous actions in the Redux paradigm?

Lyrica
I decided to use the Flux approach to implement the application, and took the implementation of Redux + React as a basis.
I read a lot about where business logic is described, about pure functions in reducers and actions, about designing the storage structure (store, state), and most importantly, the problem of asynchronous calls. In this regard, there is a little mess in my head, so I want to understand the next question a little.
Essence
There is an application that must be initialized before it starts its work. By initialization, I mean a series of actions on the part of the application, after which it is considered initialized.
Accordingly, the application has a certain isInitialized state , which is initially set to false. And in order to turn this state into true , you need to perform, for example, several actions:
- Get the first config from one source
- Get the second config from the second source
- Combine the result of these configs into one
- Tell the application that now we have initialized and we have all the data to display the first page.
- Or a sub-item, tell the application that we could not initialize and it is impossible to continue working.
Question: What is the best way to implement this?
What is the stupor :
Stupor in the right approach
- where to implement the logic of waiting for two requests and combining configs
- how to properly implement work with two asynchronous service API calls, on the results of which one state property depends.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DiMoNTD, 2016-09-23
@DiMoNTD

As a result, I used the redux-saga library.
https://github.com/yelouafi/redux-saga
What I liked about it is that you can subscribe to a specific action, execute a chain of tasks and return a new state. I won’t say, of course, that I figured it out with half a kick, but in general a couple of articles and officers helped. documentation:
https://shift.infinite.red/using-redux-saga-to-sim...
yelouafi.github.io/redux-saga/docs/api/index.html#...

A
Amazing-Space-Invader, 2016-09-18
@Amazing-Space-Invader

Configs need to be received synchronously or asynchronously? In any case, it is better to implement receiving in actions. Some manipulation too. Dispatch them when needed. Here is a tutorial on asynchronous json loading

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question