Last active
October 5, 2016 19:38
-
-
Save callmehiphop/c3145ecd142bd18300d53d0c828000bf to your computer and use it in GitHub Desktop.
simple Promise#spread decorator
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
function decorate(Promise) { | |
Promise.prototype.spread = function(yep, nope) { | |
var args = [yep ? resolver(yep) : null]; | |
if (nope) { | |
args.push(resolver(nope)); | |
} | |
return this.then.apply(this, args); | |
}; | |
function resolver(cb) { | |
return function(things) { | |
things = Array.isArray(things) ? things : [things]; | |
return cb.apply(null, things); | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment