Created
February 1, 2015 22:53
-
-
Save cjbell/3a4fcafd94735340643d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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