Skip to content

Instantly share code, notes, and snippets.

@paulparton
Last active October 13, 2016 00:08
Show Gist options
  • Save paulparton/1b7a5a14a078b65cb7c6a6866d22b38f to your computer and use it in GitHub Desktop.
Save paulparton/1b7a5a14a078b65cb7c6a6866d22b38f to your computer and use it in GitHub Desktop.
Promise indentation styles
//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