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)
This commit is contained in:
Talia 2022-03-26 12:40:50 +01:00
parent 9bb5f82302
commit 16ac15b7c3
Signed by: darkwiiplayer
GPG key ID: 7808674088232B3E

View file

@ -12,6 +12,8 @@ or
const keyToPropName = key => key.replace(/^[A-Z]/, a => "-"+a).replace(/[A-Z]/g, a => '-'+a.toLowerCase()) 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) => { const insertStyles = (rule, styles) => {
for (let [key, value] of Object.entries(styles)) for (let [key, value] of Object.entries(styles))
if (typeof value == "undefined") if (typeof value == "undefined")
@ -37,12 +39,10 @@ const createPromiseNode = promise => {
const parseArgs = (element, before, ...args) => { const parseArgs = (element, before, ...args) => {
if (element.content) element = element.content 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") if (typeof arg == "string" || typeof arg == "number")
element.insertBefore(document.createTextNode(arg), before) element.insertBefore(document.createTextNode(arg), before)
else if (arg === undefined) else if (arg === undefined || arg == null)
console.warn(`Argument is ${typeof arg}`, element)
else if (arg === null)
console.warn(`Argument is ${typeof arg}`, element) console.warn(`Argument is ${typeof arg}`, element)
else if (typeof arg == "function") else if (typeof arg == "function")
arg(element) arg(element)