Skip to content

Commit 2880e5c

Browse files
committed
If when is passed an array of promises, call the then method with an array of results
1 parent b3356b2 commit 2880e5c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/ParsePromise.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ export default class ParsePromise {
346346
*/
347347
static when(promises) {
348348
var objects;
349-
if (Array.isArray(promises)) {
349+
var arrayArgument = Array.isArray(promises);
350+
if (arrayArgument) {
350351
objects = promises;
351352
} else {
352353
objects = arguments;
@@ -355,12 +356,13 @@ export default class ParsePromise {
355356
var total = objects.length;
356357
var hadError = false;
357358
var results = [];
359+
var returnValue = arrayArgument ? [results] : results;
358360
var errors = [];
359361
results.length = objects.length;
360362
errors.length = objects.length;
361363

362364
if (total === 0) {
363-
return ParsePromise.as.apply(this, results);
365+
return ParsePromise.as.apply(this, returnValue);
364366
}
365367

366368
var promise = new ParsePromise();
@@ -371,7 +373,7 @@ export default class ParsePromise {
371373
if (hadError) {
372374
promise.reject(errors);
373375
} else {
374-
promise.resolve.apply(promise, results);
376+
promise.resolve.apply(promise, returnValue);
375377
}
376378
}
377379
};

0 commit comments

Comments
 (0)