GitXplorerGitXplorer
j

yapa

public
3 stars
0 forks
1 issues

Commits

List of commits on branch master.
Unverified
019f027868dec17a3ae4d6fc458f3bcdbdf80759

Add licence.

committed 12 years ago
Unverified
e5b7e9287a040e58d52a2343b9a862bd32b129df

Clean up README.

committed 12 years ago
Unverified
4fea0cbc74f034ea6c1430d0ebdf18ea68d80298

0.2.0

committed 12 years ago
Unverified
43f4c3a2ca9311230f8bb86ec79c44c18042ceb7

Update description and keywords.

committed 12 years ago
Unverified
323c2041758487e71db6ca5b6314d9e66e0fcd6c

Update README.

committed 12 years ago
Unverified
e01ad74dcde6f103a9735f74d818dc7eb0e96d4c

Play nice with psuedo-promises on propagation.

committed 12 years ago

README

The README file for this repository.

build status

Yapa

Yapa is an implementation of Promises/A+ with some extra methods bolted on. It passes the Promises/A+ Compliance Test Suite.

Installation

Download

$ npm install yapa

Require

var yapa = require('yapa');

API

constructor

Constructs a new promise, but you probably already knew that.

var promise = new yapa.Promise();

Promise#fulfill(value)

Transitions promise from pending state to fulfilled state. The promise's onFulfilled callbacks will be invoked in the order they were attached. value will be the argument passed to the promise's onFulfilled callbacks.

promise.fulfill('42');

Promise#reject(reason)

Transitions promise from pending state to rejected state. The promise's onRejected callbacks will be invoked in the order they were attached. reason will be the argument passed to the promise's onRejected callbacks.

promise.reject(new Error('cannot compute'));

Promise#then(onFulfilled, onRejected)

Provides an interface for accessing the promise's current or eventual fulfillment value or rejection reason. When the promise is fulfilled or rejected, the corresponding callback will be invoked. If the promise has already been fulfilled or rejected, the corresponding callback will be invoked on the next loop through the event queue.

var onFulfilled = function(value) { /* celebrate! */ }
  , onRejected = function(reason) { /* mourn */ };

promise.then(onFulfilled, onRejected);

Promise#error(onRejected)

Sugar for then(null, onRejected).

Promise#values(onFulfilled)

Similar to the then method, however rather than have onFulfilled's argument list only consist of the promise's fulfillment value, its argument list consists of the promise's fulfillment value and the fulfillment values of all of the preceding promises in the promise chain.

  promise
  .then(function() { return 123; })
  .then(function() { return 'do re mi'; })
  .values(function(start, easyAs, simpleAs) { 
    console.log(start);
    console.log('easy as %s', easyAs);
    console.log('simple as %s', simpleAs);
  });

  promise.fulfill('abc');

Testing

$ cd yapa
$ npm test

Issues

Found a bug? Create an issue on GitHub.

https://github.com/jharding/yapa/issues

Versioning

For transparency and insight into the release cycle, releases will be numbered with the follow format:

<major>.<minor>.<patch>

And constructed with the following guidelines:

  • Breaking backwards compatibility bumps the major
  • New additions without breaking backwards compatibility bumps the minor
  • Bug fixes and misc changes bump the patch

For more information on semantic versioning, please visit http://semver.org/.

License

Copyright (c) 2013 Jake Harding
Licensed under the MIT License.