Skip to content

Instantly share code, notes, and snippets.

@cjbell
Created February 1, 2015 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cjbell/3a4fcafd94735340643d to your computer and use it in GitHub Desktop.
Save cjbell/3a4fcafd94735340643d to your computer and use it in GitHub Desktop.
var API = {
get: function() {
return new Promise(function() {
// ... some code to get remotely
});
}
}
var UserAPI = {
getById: function(id) {
return API.get('/users/' + id)
.then(function(resp) {
var user = transformResp(resp); // Some kind of response transform
UserServerActionCreator.handleUserFetchSuccess(user);
})
.catch(function(resp){
UserServerActionCreator.handlerUserFetchError(resp);
});
}
};
var UserActionCreator = {
requestUser: function(userId, ctxt) {
AppDispatcher.handleViewAction({
type: ActionTypes.REQUEST_USER,
userId: userId,
ctxt: ctxt
});
UserAPI.getById(userId);
}
}
var UserServerActionCreators = {
handleUserFetchSuccess: function(user) {
AppDispatcher.handleServerAction({
type: ActionTypes.REQUEST_USER_SUCCESS,
user: user
});
},
handleUserFetchError: function(resp) {
AppDispatcher.handleServerAction({
type: ActionTypes.REQUEST_USER_ERROR,
resp: resp
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment