UNPKG

@surface/custom-element

Version:

Provides support of directives and data binding on custom elements.

17 lines (16 loc) 695 B
import { DisposableMetadata, HookableMetadata } from "@surface/core"; /** * Creates an event handler using the decorated method. * @type Event listener type. * @options Event listener options. */ export default function event(type, options) { return (target, propertyKey) => { const action = (element) => { const listener = (event) => element[propertyKey].call(element, event); element.addEventListener(type, listener, options); DisposableMetadata.from(element).add({ dispose: () => element.removeEventListener(type, listener) }); }; HookableMetadata.from(target.constructor).initializers.push(action); }; }