Skip to content

Instantly share code, notes, and snippets.

@choonkending
Created January 18, 2016 01:17
Show Gist options
  • Save choonkending/43b0e88eb3352bcf0ca0 to your computer and use it in GitHub Desktop.
Save choonkending/43b0e88eb3352bcf0ca0 to your computer and use it in GitHub Desktop.
New way to wrap jQuery deferred object if you have no choice
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