Last active
October 13, 2016 00:08
-
-
Save paulparton/1b7a5a14a078b65cb7c6a6866d22b38f to your computer and use it in GitHub Desktop.
Promise indentation styles
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
//Option 1 - function calls on the same line | |
nameOfMyservice.functionThatReturnsAPromise.then(()=>{ | |
}).then(otherFunction).then(()=>{ | |
}).catch(()=>{ | |
}); | |
//Options 2 - function calls drop to a new line | |
nameOfMyservice | |
.functionThatReturnsAPromise | |
.then(()=>{ | |
}) | |
.then(otherFunction) | |
.then(()=>{ | |
}).catch(()=>{ | |
}); | |
//avoiding inline functions | |
nameOfMyservice | |
.functionThatReturnsAPromise | |
.then(handleFirstPromiseAndReturnAnother) //<- for this callback this = functionThatReturnsAPromise | |
.then(handleSecondPromiseAndKeepThisScope.bind(this)) | |
.catch(handlePromiseErrorUsing('Error came from nameOfMyservice.functionThatReturnsAPromise')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment