* 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)
| 2582 | * Supports async conditions transparently -- returns a Promise if any condition is async. |
| 2583 | */ |
| 2584 | implicitLoopWhen(targets, whenExpr, context, forwardFn, reverseFn) { |
| 2585 | var elements = []; |
| 2586 | this.implicitLoop(targets, function(elt) { |
| 2587 | elements.push(elt); |
| 2588 | }); |
| 2589 | var conditions = elements.map(function(elt) { |
| 2590 | context.beingTested = elt; |
| 2591 | return whenExpr.evaluate(context); |
| 2592 | }); |
| 2593 | context.beingTested = null; |
| 2594 | var hasPromise = conditions.some(function(c) { |
| 2595 | return c && typeof c.then === "function"; |
| 2596 | }); |
| 2597 | if (hasPromise) { |
| 2598 | return Promise.all(conditions).then((results) => { |
| 2599 | context.result = this.#applyWhenResults(elements, results, forwardFn, reverseFn); |
| 2600 | }); |
| 2601 | } else { |
| 2602 | context.result = this.#applyWhenResults(elements, conditions, forwardFn, reverseFn); |
| 2603 | } |
| 2604 | } |
| 2605 | #applyWhenResults(elements, results, forwardFn, reverseFn) { |
| 2606 | var matched = []; |
| 2607 | for (var i = 0; i < elements.length; i++) { |
no test coverage detected