0.1.3 • Published 8 years ago

named-promise v0.1.3

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

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.

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago