Closed clsource closed 4 years ago
Okay. So then is the props
argument to the createObjectElement function completely ignored then? It seems like it shouldn't hurt if people want to optionally add properties to their objects. What do you think?
The current addChild
function works well for createDOMElement
and createSVGElement
because they need the attributes be a string to be DOM valid. But in an object the attribute can be a number or a boolean without the need to typecast to a string.
Example code with example output
(() => {
const { body, img, button } = elementBuilders(createObject);
const app = body.class`flex`(
img.class`w-full`.src`img/card-top.jpg`.alt`Sunset in the mountains`,
button.class`btn btn-lg`("Click Me"),
button.class`btn btn-lg`(200)
);
console.log(app);
console.log(JSON.stringify(app));
})();
{
"tagName": "body",
"children": [{
"tagName": "img",
"children": [],
"value": "",
"__isElement": true,
"class": "w-full",
"src": "img/card-top.jpg",
"alt": "Sunset in the mountains"
}, {
"tagName": "button",
"children": [],
"value": "Click Me",
"__isElement": true,
"class": "btn btn-lg"
}, {
"tagName": "button",
"children": [],
"value": 200,
"__isElement": true,
"class": "btn btn-lg"
}],
"value": "",
"__isElement": true,
"class": "flex"
}
Looks good.
Upon testing the
createObjectElement
I realized that theaddChild
function should be different. Since the values in child does not need the setAttributes needed in DOM.improved the function and the test example.