From 16ac15b7c366644cb8cc5836287fdd6822b2ab21 Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Sat, 26 Mar 2022 12:40:50 +0100 Subject: [PATCH] Add explicit empty value to skooma Optional arguments in skooma can be very annoying at times: html.span("foo: ", may_return_undefined()) Skooma will produce a warning to inform the user that one of their arguments is undefined as is is often unintended. The new `empty` value provides a mechanism to explicitly ignore a single argument, should it be optional html.span("foo: ", may_return_undefined() || empty) --- skooma.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/skooma.js b/skooma.js index 356fab4..6e3c477 100644 --- a/skooma.js +++ b/skooma.js @@ -12,6 +12,8 @@ or const keyToPropName = key => key.replace(/^[A-Z]/, a => "-"+a).replace(/[A-Z]/g, a => '-'+a.toLowerCase()) +export const empty = Symbol("Explicit empty argument for Skooma") + const insertStyles = (rule, styles) => { for (let [key, value] of Object.entries(styles)) if (typeof value == "undefined") @@ -37,12 +39,10 @@ const createPromiseNode = promise => { const parseArgs = (element, before, ...args) => { if (element.content) element = element.content - for (let arg of args) + for (let arg of args) if (arg !== empty) if (typeof arg == "string" || typeof arg == "number") element.insertBefore(document.createTextNode(arg), before) - else if (arg === undefined) - console.warn(`Argument is ${typeof arg}`, element) - else if (arg === null) + else if (arg === undefined || arg == null) console.warn(`Argument is ${typeof arg}`, element) else if (typeof arg == "function") arg(element)