Skip to content

Commit

Permalink
create an object if given a string
Browse files Browse the repository at this point in the history
  • Loading branch information
keithamus committed Oct 23, 2024
1 parent bd69f5d commit 8cc9495
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/lazy-define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,12 @@ export function lazyDefine(object: Record<string, () => void>): void
export function lazyDefine(tagName: string, callback: () => void): void
export function lazyDefine(tagNameOrObj: string | Record<string, () => 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)
}

Expand Down

0 comments on commit 8cc9495

Please sign in to comment.