Temporarily patch an upstream issue in mithril

This commit is contained in:
Steve Purcell 2014-05-27 17:39:40 +01:00
parent 75c492f9b7
commit fe786ec49d

View file

@ -11,6 +11,31 @@
// TODO Show recent github events on package pages where applicable
// TODO Voting / starring
// Temporary fix pending https://github.com/lhorie/mithril.js/issues/101 upstream
m.sync = function(args) {
var method = "resolve"
function synchronizer(pos, resolved) {
return function(value) {
--outstanding
results[pos] = value
if (!resolved) method = "reject"
if (outstanding == 0) {
deferred.promise(results)
deferred[method](results)
}
return value
}
}
var deferred = m.deferred()
var outstanding = args.length
var results = new Array(outstanding)
for (var i = 0; i < args.length; i++) {
args[i].then(synchronizer(i, true), synchronizer(false))
}
return deferred.promise
}
//////////////////////////////////////////////////////////////////////////////
// Helpers