Created
February 12, 2015 13:35
-
-
Save ricardobeat/77a6453069448c2ea5a0 to your computer and use it in GitHub Desktop.
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
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