MCPcopy Create free account
hub / github.com/bigskysoftware/_hyperscript / implicitLoopWhen

Method implicitLoopWhen

www/js/_hyperscript-max.js:2583–2603  ·  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

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