Fix error handling arrays in skooma.js

This commit is contained in:
Talia 2024-01-24 09:51:49 +01:00
parent 24ea67bf81
commit 2f95afbcb7

View file

@ -52,7 +52,7 @@ const getCustom = args => args.reduce(
const isElement = object => HTMLElement.prototype.isPrototypeOf(object) const isElement = object => HTMLElement.prototype.isPrototypeOf(object)
const isReactive = object => !(object instanceof HTMLElement) export const isReactive = object => !(object instanceof HTMLElement)
&& (object instanceof EventTarget) && (object instanceof EventTarget)
&& ("value" in object) && ("value" in object)
@ -63,6 +63,8 @@ const toChild = arg => {
return arg return arg
} else if (isReactive(arg)) { } else if (isReactive(arg)) {
return reactiveChild(arg) return reactiveChild(arg)
} else {
return document.createComment("Placeholder for reactive content")
} }
} }
@ -148,6 +150,9 @@ const setReactiveAttribute = (element, attribute, reactive, abortController) =>
const parseArgs = (element, ...args) => { const parseArgs = (element, ...args) => {
if (element.content) element = element.content if (element.content) element = element.content
for (const arg of args) if (arg !== empty) { for (const arg of args) if (arg !== empty) {
if (arg instanceof Array) {
parseArgs(element, ...arg)
} else {
const child = toChild(arg) const child = toChild(arg)
if (child) if (child)
element.append(child) element.append(child)
@ -157,12 +162,11 @@ const parseArgs = (element, ...args) => {
parseArgs(element, arg()) parseArgs(element, arg())
else if (typeof arg == "function") else if (typeof arg == "function")
arg(element) arg(element)
else if ("length" in arg)
parseArgs(element, ...arg)
else else
for (const key in arg) for (const key in arg)
setAttribute(element, key, arg[key]) setAttribute(element, key, arg[key])
} }
}
} }
const node = (name, args, options) => { const node = (name, args, options) => {