Cranberry is a Promises/A+ implementation written as a lightweight layer on top of Promise
with additional features not in the promises/a+ spec. It passes the Promises/A+ Test Suite.
If you have a browser baseline that includes most relatively recent browsers you can use Promise
without a polyfill. This is great! Promise implementations have additional features that make them useful but the downside is that they can make stacks grow quite long. Cranberry works around this issue by using native promises under the hood.
npm install cranberry
var Promise = require('cranberry'); //or give it any name you like
See MDN docs
See MDN docs
Like the call above, but it's only run is the rejection value of the promise it's called on is an instance of constructor
.
Only run if called on a fulfilled promise. Returns a new promise (res
) whose resolution value is the same as the promise it's called on. If func
returns a promise, the resolution of the returned promise is delayed until said promise is settled. If the promise returned by func
is rejected (or if func
throws), the returned promise is rejected as well, with the same value.
Like .tap(), but calls func
even if run on a rejected promise.
Like then, but if the resolution value of the promise it's called on is an array, the it is used as the arguments array to onFulfilled
.
Promise.resolve([1, 2]).spread(function(one, two)){
//one + two === 3
});
See MDN docs
See MDN docs
See MDN docs