Skip to content

Commit

Permalink
Using when.map where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
briancavalier committed Nov 5, 2011
1 parent 275bbca commit daea1e7
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions wire.js
Expand Up @@ -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
Expand Down

0 comments on commit daea1e7

Please sign in to comment.