Skip to content

Promise patterns #4

Description

@anandkumarpatel

Let us discuss our new coding patterns now that we moved everything to promises:

Method 1 Linear program w/ comments

Promise.try(() {
  // JSDoc
  ... code ...
})
.then(doSomething1 () {
  // JSDoc
  ... code ...
})
.then(doSomething2 () {
  // JSDoc
  ... code ...
})
.then(doSomething3 () {
  // JSDoc
  ... code ...
})

Pro: looks linear
Cons: unit testing is harder, requires more setup

Method 2 Functional

Promise.try(() {
 return fn1()
})
.then(() {
  return fn2()
})
.then(() {
 return fn3()
})
.then(() {
 return fn4()
})
// JSDoc
fn1 = {
  ... code ...
}
// JSDoc
fn2 = {
  ... code ...
}
// JSDoc
fn3 = {
  ... code ...
}
// JSDoc
fn4 = {
  ... code ...
}

Pro: functions are broken up into smaller components. Each function can have proper unit tests and docs
Con: have to look at different areas on the page to understand full function.

Any other methods people prefer & which do you like the most?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions