yapawapa
v0.1.0
Published
Decorator for Yapa promises
Downloads
3
Readme
Yapawapa
Yapawapa is a decorator of Yapa promises. It makes it easy to add arbitrary functions to the prototype of a Yapa promise constructor. Those functions can then seamlessly be used within a promise chain.
Installation
Download
$ npm install yapawapa
Require
var yapawapa = require('yapawapa');
API
yapawapa.decorate(decorations)
Returns a promise constructor whose prototype has been decorated with decorations
. Functions found in decorations
will be wrapped so that they can be used seamlessly in a promise chain. Getters and setters in decorations
will be wrapped so that they are called on the underlying context of the promise instance.
Promise(context)
The promise constructor generated by decorate
. All functions that were added through decorate
will be called in the context of context
. All getters and setters will be read/write-throughs to the matching properties of context
.
Example
var Promise = yapawapa.decorate({
get name() {
return this.name;
}
, syncMethod: function() {
return this.name + ' sync';
}
, asyncMethod: function(cb) {
process.nextTick( function() { cb(null, this.name + ' async'); });
}
});
var promise = Promise({ name: 'yapawapa' });
assert.equal(promise.name, 'yapawapa');
promise
.syncMethod()
.asyncMethod()
.values(function(syncValue, asyncValue) {
assert.equal(syncValue, 'yapawapa is sync');
assert.equal(asyncValue, 'yapawapa is async');
});
promise.fulfill();
Testing
$ cd yapawapa
$ npm test
Issues
Found a bug? Create an issue on GitHub.
https://github.com/jharding/yapawapa/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.