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
1 changed files with 18 additions and 14 deletions

View File

@ -52,7 +52,7 @@ const getCustom = args => args.reduce(
const isElement = object => HTMLElement.prototype.isPrototypeOf(object)
const isReactive = object => !(object instanceof HTMLElement)
export const isReactive = object => !(object instanceof HTMLElement)
&& (object instanceof EventTarget)
&& ("value" in object)
@ -63,6 +63,8 @@ const toChild = arg => {
return arg
} else if (isReactive(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) => {
if (element.content) element = element.content
for (const arg of args) if (arg !== empty) {
if (arg instanceof Array) {
parseArgs(element, ...arg)
} else {
const child = toChild(arg)
if (child)
element.append(child)
@ -157,12 +162,11 @@ const parseArgs = (element, ...args) => {
parseArgs(element, arg())
else if (typeof arg == "function")
arg(element)
else if ("length" in arg)
parseArgs(element, ...arg)
else
for (const key in arg)
setAttribute(element, key, arg[key])
}
}
}
const node = (name, args, options) => {