* 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)
| 2569 | * Supports async conditions transparently -- returns a Promise if any condition is async. |
| 2570 | */ |
| 2571 | implicitLoopWhen(targets, whenExpr, context, forwardFn, reverseFn) { |
| 2572 | var elements = []; |
| 2573 | this.implicitLoop(targets, function(elt) { |
| 2574 | elements.push(elt); |
| 2575 | }); |
| 2576 | var conditions = elements.map(function(elt) { |
| 2577 | context.beingTested = elt; |
| 2578 | return whenExpr.evaluate(context); |
| 2579 | }); |
| 2580 | context.beingTested = null; |
| 2581 | var hasPromise = conditions.some(function(c) { |
| 2582 | return c && typeof c.then === "function"; |
| 2583 | }); |
| 2584 | if (hasPromise) { |
| 2585 | return Promise.all(conditions).then((results) => { |
| 2586 | context.result = this.#applyWhenResults(elements, results, forwardFn, reverseFn); |
| 2587 | }); |
| 2588 | } else { |
| 2589 | context.result = this.#applyWhenResults(elements, conditions, forwardFn, reverseFn); |
| 2590 | } |
| 2591 | } |
| 2592 | #applyWhenResults(elements, results, forwardFn, reverseFn) { |
| 2593 | var matched = []; |
| 2594 | for (var i = 0; i < elements.length; i++) { |
no test coverage detected