F
F
fullj02016-06-05 22:51:10
React
fullj0, 2016-06-05 22:51:10

Where, according to the concept of redux, would it be correct to store an object - a data source for calculating state?

My application works as follows, when loading the page, I, using isomorphic-fetch and redux-thunk, load a json file with a large amount of statistical data (while it is loading, I inform the user about this by the preloader). I call the load function in the componetDidMount method of the only smart component in the application. After loading, the initial state is displayed - the user interacts with the page by selecting certain options - depending on the selected options, the object with the received statistical data is subjected to not weak processing (various map, filter, groupBy, reduce, etc.), as a result, in state is passed only a small part of the original object. And so I thought, where would it be right to store this object. Keeping it in state is probably not correct. It turns out I have to reducer (reducers/myReducer. js) declare an object let = myStats = {}; in the function that processes the action of loading a file with statistical data, assign the json received from the file and parsed to this object. And in all other action handlers (which are called depending on the user's actions), already refer to this object to calculate the current state. Am I speaking correctly? If not, please correct me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vsuhachev, 2016-06-06
@vsuhachev

Personally, I would do the same. The only thing is that you do not need to load the processed data into the component state. It seems to me more correct to store the current user's choice in the state of the component, and generate data on the fly from the reducer. Or, if it takes a long time to generate, then you can make more reducers that will store the results of calculations to speed up the calculations.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question