* Iterate over targets with a when condition, applying forward or reverse per element. * Supports async conditions transparently -- returns a Promise if any condition is async.
(targets, whenExpr, context, forwardFn, reverseFn)
| 586 | * Supports async conditions transparently -- returns a Promise if any condition is async. |
| 587 | */ |
| 588 | implicitLoopWhen(targets, whenExpr, context, forwardFn, reverseFn) { |
| 589 | var elements = []; |
| 590 | this.implicitLoop(targets, function (elt) { elements.push(elt); }); |
| 591 | |
| 592 | var conditions = elements.map(function (elt) { |
| 593 | context.beingTested = elt; |
| 594 | return whenExpr.evaluate(context); |
| 595 | }); |
| 596 | context.beingTested = null; |
| 597 | |
| 598 | var hasPromise = conditions.some(function (c) { return c && typeof c.then === "function"; }); |
| 599 | if (hasPromise) { |
| 600 | return Promise.all(conditions).then((results) => { |
| 601 | context.result = this.#applyWhenResults(elements, results, forwardFn, reverseFn); |
| 602 | }); |
| 603 | } else { |
| 604 | context.result = this.#applyWhenResults(elements, conditions, forwardFn, reverseFn); |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | #applyWhenResults(elements, results, forwardFn, reverseFn) { |
| 609 | var matched = []; |
no test coverage detected