I am trying to follow the flux architecture from the facebook sample found at
https://github.com/facebook/flux/tree/master/examples/flux-todomvc
Where is this architecture would you call your api to get data from a remote service?
The AppContainer has a getState method which gets the get initial state of the store. This would be null since the database call hasn’t happened yet. I could make the api call in the Action creator. But where do i trigger this action?
AppContainer.js
function getStores() {
return [
TodoStore
];
}
function getState() {
return {
todos: TodoStore.getState()
};
}
2
Answers
You should create an action dispatcher, that fires the fetch request and dispatches the action with the fetch result as payload. Handle this action dispatcher over via
mapDispatchToProps
and call it inside your component viacomponentDidMount
cycle method.you should create Actions class, that will have methods. This method will dispatch actions to store, and send ajax data.
example of one
Actions
class method:so in fact you will have 2-3 dispatched events: