Skip to content

Instantly share code, notes, and snippets.

@julianlconnor
Created April 24, 2014 19:56
Show Gist options
  • Save julianlconnor/11267449 to your computer and use it in GitHub Desktop.
Save julianlconnor/11267449 to your computer and use it in GitHub Desktop.
hydrating route proto
_hydrate: function() {
var args = arguments;
var keys = _.keys(this.requires);
var values = _.values(this.requires);
/**
* Create a list of promises.
*/
var promises = values.map(function(fn) {
return fn.apply(this, args);
}.bind(this));
/**
* Associate the return values of the promises to keys on `this.data`.
*/
return q.all(promises).spread(function() {
_.each(arguments, function(payload, index) {
var key = keys[index];
this.data[key] = payload;
}, this);
}.bind(this));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment