I'm new to redux and writing a frontend application that holds a global state which is retrieved on startup via ajax and then updated via poll/push as new data is retrieved. On navigation to each url there's an actor which dispatches to an action which then calls a reducer that overwrites part of the viewState
object with a filtered view of this globalState
. e.g. navigation to the url /items/filter/a
would adjust the viewState
to the following:
state {
viewState: {
items: [{id: 1, value: 'a'}]
}
globalState: {
items: [{id: 1, value: 'a'},
{id: 2, value: 'b'},
{id: 3, value: 'c']}
}
}
After this step then ReactDOM.render()
is called via another actor and all the components re-render with the updated values in viewState
(this isn't my code its straight from the unicorn starter pack)
I'm wondering a) if this is a sensible way to go about structuring an application of this type. and b) what is the best way of initializing the globalState
variable on application bootup and then listening for updates (which would potentially then update the viewState
if that object with that id is currently in the viewState
)