Fix error handling arrays in skooma.js
This commit is contained in:
parent
24ea67bf81
commit
2f95afbcb7
1 changed files with 18 additions and 14 deletions
32
skooma.js
32
skooma.js
|
@ -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,20 +150,22 @@ 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) {
|
||||||
const child = toChild(arg)
|
if (arg instanceof Array) {
|
||||||
if (child)
|
|
||||||
element.append(child)
|
|
||||||
else if (arg === undefined || arg == null)
|
|
||||||
console.warn(`An argument of type ${typeof arg} has been ignored`, element)
|
|
||||||
else if (typeof arg == "function" && arg.length == 0)
|
|
||||||
parseArgs(element, arg())
|
|
||||||
else if (typeof arg == "function")
|
|
||||||
arg(element)
|
|
||||||
else if ("length" in arg)
|
|
||||||
parseArgs(element, ...arg)
|
parseArgs(element, ...arg)
|
||||||
else
|
} else {
|
||||||
for (const key in arg)
|
const child = toChild(arg)
|
||||||
setAttribute(element, key, arg[key])
|
if (child)
|
||||||
|
element.append(child)
|
||||||
|
else if (arg === undefined || arg == null)
|
||||||
|
console.warn(`An argument of type ${typeof arg} has been ignored`, element)
|
||||||
|
else if (typeof arg == "function" && arg.length == 0)
|
||||||
|
parseArgs(element, arg())
|
||||||
|
else if (typeof arg == "function")
|
||||||
|
arg(element)
|
||||||
|
else
|
||||||
|
for (const key in arg)
|
||||||
|
setAttribute(element, key, arg[key])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue