Created
March 1, 2014 20:52
-
-
Save joelkallman/9297074 to your computer and use it in GitHub Desktop.
Ember RSVP spread method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (RSVP) { | |
if (!RSVP) { | |
return; | |
} | |
/** | |
Spread is utilized with the all() method. | |
Basic Usage: | |
------------ | |
```js | |
new Ember.RSVP.all([findUser(), findSettings()]).spread(function (user, setting) { | |
// have access to both user and settings, but as parameters rather than an array | |
}, function(reason){ | |
// one of the promises is unavailable, and you are given the reason why | |
}); | |
``` | |
@method spread | |
@param {Function} onFulfilled | |
@param {Function} onRejected | |
@param {String} label optional string for labeling the promise. | |
Useful for tooling. | |
@return {Promise} | |
*/ | |
RSVP.Promise.prototype.spread = function (onFulfillment, onRejection, label) { | |
return this.then(function (array) { | |
return onFulfillment.apply(void 0, array); | |
}, onRejection, label); | |
}; | |
})(Ember.RSVP); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment