-
-
Save cheeyeo/9efa9be3c132ea1e25ed to your computer and use it in GitHub Desktop.
This file contains hidden or 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