named-promise

0.1.3 • Public • Published

Synopsis

ES6 Promise syntax sugar allowing hash return values in a chain.

Code Example

Array

Promise.resolve('result1')
  .then(function(res) {
    return Promise.all([
      res, // result1
      Promise.resolve('result2')
    ]);
  })
  .then(function(arr) {
    var result1 = arr[0];
    var result2 = arr[1];
    // do something with result1 and result2
  })

Hash

Promise.resolve('result1')
  .then(function(res) {
    return NamedPromise.all({
      result1: res,
      result2: Promise.resolve('result2')
    });
  })
  .then(function(context) {
    // do something with context
    console.log(context.result1);
    console.log(context.result2);
    return NamedPromise.assign(context, {
      result3: Promise.resolve('result3')
    });
  })
  .then(function(context) {
    // you still have access to all the previous results
    console.log(context.result1);
    console.log(context.result2);
    console.log(context.result3);
  })
  .catch(function(err) { console.log(err); })

Installation

For npm

npm install named-promise

Contributing

npm install -g gulp
gulp build

Tests

npm install jasmine
npm test

API References

gulp doc

Contributors

Yuanyuan Ryan Zhang

License

This software is licensed under the MIT License.

Readme

Keywords

Package Sidebar

Install

npm i named-promise

Weekly Downloads

1

Version

0.1.3

License

MIT

Last publish

Collaborators

  • ryanzyy