Created
April 24, 2014 19:56
-
-
Save julianlconnor/11267449 to your computer and use it in GitHub Desktop.
hydrating route proto
This file contains 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
_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