Skip to content

Instantly share code, notes, and snippets.

@ricardobeat
Created February 12, 2015 13:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ricardobeat/77a6453069448c2ea5a0 to your computer and use it in GitHub Desktop.
Save ricardobeat/77a6453069448c2ea5a0 to your computer and use it in GitHub Desktop.
Promise.prototype.spread = function (fn) {
this.then(function (values) {
fn.apply(this, values)
})
}
function when () {
var requirements = Array.prototype.slice.call(arguments, 0)
return Promise.all(requirements.map(function(name){
console.log(name)
switch (typeof name) {
case 'string' : return when.conditions[name].call(this)
case 'function' : return fn.call(this)
default : return name
}
}))
}
when.conditions = {}
when.define = function (name, fn) {
when.conditions[name] = fn
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment