Skip to content

Commit da15330

Browse files
keithamuskoddsson
andcommitted
avoid costly re-initialization of attrs
Co-authored-by: Kristján Oddsson <koddsson@gmail.com>
1 parent 13c78ef commit da15330

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/attr.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ export function attr<K extends string>(proto: Record<K, attrValue>, key: K): voi
3434
* This is automatically called as part of `@controller`. If a class uses the
3535
* `@controller` decorator it should not call this manually.
3636
*/
37+
const initialized = new WeakSet<Element>()
3738
export function initializeAttrs(instance: HTMLElement, names?: Iterable<string>): void {
39+
if (initialized.has(instance)) return
40+
initialized.add(instance)
3841
if (!names) names = getAttrNames(Object.getPrototypeOf(instance))
3942
for (const key of names) {
4043
const value = (<Record<PropertyKey, unknown>>(<unknown>instance))[key]

0 commit comments

Comments
 (0)