Skip to content

Instantly share code, notes, and snippets.

@joelkallman
Created March 1, 2014 20:52
Show Gist options
  • Save joelkallman/9297074 to your computer and use it in GitHub Desktop.
Save joelkallman/9297074 to your computer and use it in GitHub Desktop.
Ember RSVP spread method
(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