MCPcopy Index your code
hub / github.com/bigskysoftware/_hyperscript / implicitLoopWhen

Method implicitLoopWhen

www/js/_hyperscript.esm.js:2582–2602  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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

Callers 4

resolveMethod · 0.45
resolveMethod · 0.45
resolveMethod · 0.45
resolveMethod · 0.45

Calls 3

implicitLoopMethod · 0.95
#applyWhenResultsMethod · 0.95
evaluateMethod · 0.45

Tested by

no test coverage detected