From 2f95afbcb78ca9a23077f4250a3efdd99c99a6d4 Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Wed, 24 Jan 2024 09:51:49 +0100 Subject: [PATCH] Fix error handling arrays in skooma.js --- skooma.js | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/skooma.js b/skooma.js index 3c94abd..8e4edd5 100644 --- a/skooma.js +++ b/skooma.js @@ -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,20 +150,22 @@ const setReactiveAttribute = (element, attribute, reactive, abortController) => const parseArgs = (element, ...args) => { if (element.content) element = element.content for (const arg of args) if (arg !== empty) { - const child = toChild(arg) - 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) + if (arg instanceof Array) { parseArgs(element, ...arg) - else - for (const key in arg) - setAttribute(element, key, arg[key]) + } else { + const child = toChild(arg) + 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]) + } } }