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

Method resolve

www/js/_hyperscript-max.js:7666–7748  ·  view source on GitHub ↗
(context, { to, classRefs, css, value })

Source from the content-addressed store, hash-verified

7664 }
7665 }
7666 resolve(context, { to, classRefs, css, value }) {
7667 var runtime2 = context.meta.runtime;
7668 var cmd = this;
7669 runtime2.nullCheck(to, this.toExpr);
7670 var result;
7671 if (this.variant === "collection") {
7672 if (Array.isArray(to)) {
7673 to.push(value);
7674 } else if (to instanceof Set) {
7675 to.add(value);
7676 } else if (to instanceof Map) {
7677 throw new Error("Use 'set myMap[key] to value' for Maps");
7678 } else {
7679 throw new Error("Cannot add to " + typeof to);
7680 }
7681 runtime2.notifyMutation(to);
7682 return runtime2.findNext(this, context);
7683 } else if (this.variant === "class") {
7684 runtime2.forEach(classRefs, function(classRef) {
7685 if (cmd.when) {
7686 result = runtime2.implicitLoopWhen(
7687 to,
7688 cmd.when,
7689 context,
7690 function(t) {
7691 if (t instanceof Element) t.classList.add(classRef.className);
7692 },
7693 function(t) {
7694 if (t instanceof Element) t.classList.remove(classRef.className);
7695 }
7696 );
7697 } else {
7698 runtime2.implicitLoop(to, function(t) {
7699 if (t instanceof Element) t.classList.add(classRef.className);
7700 });
7701 }
7702 });
7703 } else if (this.variant === "attribute") {
7704 var attributeRef = this.attributeRef;
7705 if (this.when) {
7706 result = runtime2.implicitLoopWhen(
7707 to,
7708 this.when,
7709 context,
7710 function(t) {
7711 t.setAttribute(attributeRef.name, attributeRef.value);
7712 },
7713 function(t) {
7714 t.removeAttribute(attributeRef.name);
7715 }
7716 );
7717 } else {
7718 runtime2.implicitLoop(to, function(t) {
7719 t.setAttribute(attributeRef.name, attributeRef.value);
7720 });
7721 }
7722 } else {
7723 if (this.when) {

Callers

nothing calls this directly

Calls 8

_cssPropertyNamesFunction · 0.70
_removeCssPropertiesFunction · 0.70
nullCheckMethod · 0.45
notifyMutationMethod · 0.45
findNextMethod · 0.45
forEachMethod · 0.45
implicitLoopWhenMethod · 0.45
implicitLoopMethod · 0.45

Tested by

no test coverage detected