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

Method implicitLoopWhen

src/core/runtime/runtime.js:588–606  ·  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

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 = [];

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