From 3a8e33aa036cc09ed3e993aa05da958c1ea0e210 Mon Sep 17 00:00:00 2001 From: Keith Cirkel Date: Wed, 23 Oct 2024 15:04:25 +0100 Subject: [PATCH] create an object if given a string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kristján Oddsson --- src/lazy-define.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/lazy-define.ts b/src/lazy-define.ts index 0e603ee..016b886 100644 --- a/src/lazy-define.ts +++ b/src/lazy-define.ts @@ -85,15 +85,12 @@ export function lazyDefine(object: Record void>): void export function lazyDefine(tagName: string, callback: () => void): void export function lazyDefine(tagNameOrObj: string | Record void>, singleCallback?: () => void) { if (typeof tagNameOrObj === 'string' && singleCallback) { - if (!dynamicElements.has(tagNameOrObj)) dynamicElements.set(tagNameOrObj, new Set<() => void>()) - dynamicElements.get(tagNameOrObj)!.add(singleCallback) - } else { - for (const [tagName, callback] of Object.entries(tagNameOrObj)) { - if (!dynamicElements.has(tagName)) dynamicElements.set(tagName, new Set<() => void>()) - dynamicElements.get(tagName)!.add(callback) - } + tagNameOrObj = {[tagNameOrObj]: singleCallback} + } + for (const [tagName, callback] of Object.entries(tagNameOrObj)) { + if (!dynamicElements.has(tagName)) dynamicElements.set(tagName, new Set<() => void>()) + dynamicElements.get(tagName)!.add(callback) } - observe(document) }