Skip to content

Commit

Permalink
Support inverted bound element attribute values
Browse files Browse the repository at this point in the history
  • Loading branch information
alexyuly committed Oct 19, 2024
1 parent 072f012 commit b2ba822
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function applyDataToDomElement(domElement, data, context) {
if (slotName) {
const slotData = getNestedValue(data, slotName);

if (slotData != null) {
if (slotData) {
slot.replaceWith(slotData);
}
}
Expand All @@ -87,13 +87,16 @@ function applyDataToDomElementAttributes(domElement, data, context) {
for (const attribute of attributes) {
if (attribute.name.startsWith(":")) {
const targetAttributeName = attribute.name.slice(1);
const targetAttributeValue = getNestedValue(data, attribute.value);

const targetAttributeValue = attribute.value.startsWith("!")
? !getNestedValue(data, attribute.value.slice(1))
: getNestedValue(data, attribute.value);

const targetAttributeValueSerialized = isImportedElement
? JSON.stringify(targetAttributeValue)
: targetAttributeValue;

if (targetAttributeValueSerialized != null) {
if (targetAttributeValueSerialized) {
domElement.setAttribute(
targetAttributeName,
targetAttributeValueSerialized
Expand Down Expand Up @@ -179,15 +182,15 @@ exports.getComponentFromFs = async function getComponentFromFs(

if (cachedComponent) {
console.log(
"[viewscript-ssr] getComponentFromFs cache hit for",
"[viewscript-server] getComponentFromFs cache hit for",
componentDir
);

return cachedComponent;
}

console.log(
"[viewscript-ssr] getComponentFromFs cache miss for",
"[viewscript-server] getComponentFromFs cache miss for",
componentDir
);
}
Expand Down Expand Up @@ -258,8 +261,6 @@ exports.renderComponent = async function renderComponent(
componentDom.window.document.head.appendChild(style);
}

// TODO Support dot class name syntax?

const serializedDom = componentDom.serialize();

return serializedDom;
Expand Down

0 comments on commit b2ba822

Please sign in to comment.