Commit 8c11dcc8 authored by Stefan Penner's avatar Stefan Penner

refactor RSVP.all to just use a promise directly

parent 55398c39
......@@ -32,45 +32,43 @@ var define, requireModule;
})();
define("rsvp/all",
["rsvp/defer","exports"],
["rsvp/promise","exports"],
function(__dependency1__, __exports__) {
"use strict";
var defer = __dependency1__.defer;
var Promise = __dependency1__.Promise;
function all(promises) {
var results = [], deferred = defer(), remaining = promises.length;
if (remaining === 0) {
deferred.resolve([]);
}
return new Promise(function(resolve, reject) {
var results = [], remaining = promises.length;
var resolver = function(index) {
return function(value) {
resolveAll(index, value);
};
};
if (remaining === 0) {
resolve([]);
}
var resolveAll = function(index, value) {
results[index] = value;
if (--remaining === 0) {
deferred.resolve(results);
function resolver(index) {
return function(value) {
resolveAll(index, value);
};
}
};
var rejectAll = function(error) {
deferred.reject(error);
};
function resolveAll(index, value) {
results[index] = value;
if (--remaining === 0) {
resolve(results);
}
}
for (var i = 0; i < promises.length; i++) {
if (promises[i] && typeof promises[i].then === 'function') {
promises[i].then(resolver(i), rejectAll);
} else {
resolveAll(i, promises[i]);
for (var i = 0; i < promises.length; i++) {
if (promises[i] && typeof promises[i].then === 'function') {
promises[i].then(resolver(i), reject);
} else {
resolveAll(i, promises[i]);
}
}
}
return deferred.promise;
});
}
__exports__.all = all;
});
......
This diff is collapsed.
define(
["rsvp/defer","exports"],
["rsvp/promise","exports"],
function(__dependency1__, __exports__) {
"use strict";
var defer = __dependency1__.defer;
var Promise = __dependency1__.Promise;
function all(promises) {
var results = [], deferred = defer(), remaining = promises.length;
return new Promise(function(resolve, reject) {
var results = [], remaining = promises.length;
if (remaining === 0) {
deferred.resolve([]);
}
var resolver = function(index) {
return function(value) {
resolveAll(index, value);
};
};
if (remaining === 0) {
resolve([]);
}
var resolveAll = function(index, value) {
results[index] = value;
if (--remaining === 0) {
deferred.resolve(results);
function resolver(index) {
return function(value) {
resolveAll(index, value);
};
}
};
var rejectAll = function(error) {
deferred.reject(error);
};
function resolveAll(index, value) {
results[index] = value;
if (--remaining === 0) {
resolve(results);
}
}
for (var i = 0; i < promises.length; i++) {
if (promises[i] && typeof promises[i].then === 'function') {
promises[i].then(resolver(i), rejectAll);
} else {
resolveAll(i, promises[i]);
for (var i = 0; i < promises.length; i++) {
if (promises[i] && typeof promises[i].then === 'function') {
promises[i].then(resolver(i), reject);
} else {
resolveAll(i, promises[i]);
}
}
}
return deferred.promise;
});
}
__exports__.all = all;
});
import { defer } from "rsvp/defer";
import { Promise } from "rsvp/promise";
function all(promises) {
var results = [], deferred = defer(), remaining = promises.length;
return new Promise(function(resolve, reject) {
var results = [], remaining = promises.length;
if (remaining === 0) {
deferred.resolve([]);
}
var resolver = function(index) {
return function(value) {
resolveAll(index, value);
};
};
if (remaining === 0) {
resolve([]);
}
var resolveAll = function(index, value) {
results[index] = value;
if (--remaining === 0) {
deferred.resolve(results);
function resolver(index) {
return function(value) {
resolveAll(index, value);
};
}
};
var rejectAll = function(error) {
deferred.reject(error);
};
function resolveAll(index, value) {
results[index] = value;
if (--remaining === 0) {
resolve(results);
}
}
for (var i = 0; i < promises.length; i++) {
if (promises[i] && typeof promises[i].then === 'function') {
promises[i].then(resolver(i), rejectAll);
} else {
resolveAll(i, promises[i]);
for (var i = 0; i < promises.length; i++) {
if (promises[i] && typeof promises[i].then === 'function') {
promises[i].then(resolver(i), reject);
} else {
resolveAll(i, promises[i]);
}
}
}
return deferred.promise;
});
}
export { all };
\ No newline at end of file
export { all };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment