Created
January 18, 2016 01:17
-
-
Save choonkending/43b0e88eb3352bcf0ca0 to your computer and use it in GitHub Desktop.
New way to wrap jQuery deferred object if you have no choice
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
new Promise((resolve, reject) => { | |
existingAjaxLibraryWrapper.callAPI() | |
.done(res => { | |
resolve(res); | |
}) | |
.fail(err => { | |
reject(new Error("Oops!")); | |
}); | |
}) | |
.then(res => { | |
// Do something with this | |
// E.g. if you're using redux | |
// dispatch(requestSuccess(res)); | |
}) | |
.catch(err => { | |
// Do something with this error | |
// E.g. if you're using redux | |
// dispatch(requestFailed(err.message)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment