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

Method resolve

www/js/_hyperscript.esm.js:7665–7747  ·  view source on GitHub ↗
(context, { to, classRefs, css, value })

Source from the content-addressed store, hash-verified

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