Permalink
Browse files

Using when.map where possible

  • Loading branch information...
1 parent 275bbca commit daea1e7a922c4088fdebb20cdb7a181b577071d1 @briancavalier briancavalier committed Nov 5, 2011
Showing with 5 additions and 19 deletions.
  1. +5 −19 wire.js
View
24 wire.js
@@ -561,34 +561,20 @@
}
function createArray(arrayDef, name) {
- var result, promises, itemPromise, item, id, i;
-
+ var result, id;
result = [];
if (arrayDef.length) {
- promises = [];
-
- for (i = 0; (item = arrayDef[i]); i++) {
- id = item.id || name + '[' + i + ']';
- itemPromise = result[i] = createItem(arrayDef[i], id);
- promises.push(itemPromise);
-
- resolveArrayValue(itemPromise, result, i);
- }
-
- result = chain(whenAll(promises), defer(), result);
+
+ result = when.map(arrayDef, function(item) {
+ return createItem(item, id);
+ });
}
return result;
}
- function resolveArrayValue(promise, array, i) {
- when(promise, function(value) {
- array[i] = value;
- });
- }
-
function createModule(spec, name) {
// Look for a factory, then use it to create the object

0 comments on commit daea1e7

Please sign in to comment.