@joist/element
Version:
Intelligently apply styles to WebComponents
19 lines (14 loc) • 491 B
text/typescript
import { type AttrChangedCallback, metadataStore } from "./metadata.js";
export function attrChanged(...names: string[]) {
return function attrChangedDecorator<This extends HTMLElement>(
cb: AttrChangedCallback,
ctx: ClassMethodDecoratorContext<This>,
): void {
const meta = metadataStore.read(ctx.metadata);
for (const name of names) {
const val = meta.attrChanges.get(name) ?? new Set();
val.add(cb);
meta.attrChanges.set(name, val);
}
};
}