Skip to content

Commit 3bb722f

Browse files
koddssonkeithamus
andcommitted
Implement meta function
Co-authored-by: Keith Cirkel <[email protected]>
1 parent 03b1191 commit 3bb722f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/core.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {defineObservedAttributes, initializeAttrs} from './attr.js'
55
import type {CustomElement} from './custom-element.js'
66

77
const instances = new WeakSet<Element>()
8+
const symbol = Symbol.for('catalyst')
89

910
export function initializeInstance(instance: HTMLElement, connect?: (this: HTMLElement) => void): void {
1011
instance.toggleAttribute('data-catalyst', true)
@@ -38,3 +39,18 @@ export function initializeClass(classObject: CustomElement): void {
3839
export function initialized(el: Element): boolean {
3940
return instances.has(el)
4041
}
42+
43+
export function meta(proto: Record<PropertyKey, unknown>, name: string): Set<string> {
44+
if (!Object.prototype.hasOwnProperty.call(proto, symbol)) {
45+
const parent = proto[symbol] as Map<string, Set<string>> | undefined
46+
const map = (proto[symbol] = new Map<string, Set<string>>())
47+
if (parent) {
48+
for (const [key, value] of parent) {
49+
map.set(key, new Set(value))
50+
}
51+
}
52+
}
53+
const map = proto[symbol] as Map<string, Set<string>>
54+
if (!map.has(name)) map.set(name, new Set<string>())
55+
return map.get(name)!
56+
}

0 commit comments

Comments
 (0)