Skip to content

Instantly share code, notes, and snippets.

@deebloo
Last active November 4, 2016 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deebloo/f31920d0d19906a8b0003398f858607b to your computer and use it in GitHub Desktop.
Save deebloo/f31920d0d19906a8b0003398f858607b to your computer and use it in GitHub Desktop.
Typescript declarations and decorators for custom elements
export interface CustomElementConfig {
tagName: string;
options?: {
extends: string;
};
}
/**
* @CustomElement({
* tagName: 'my-element'
* })
* class MyElement extends HTMLElement { }
*/
export const CustomElement = (config: CustomElementConfig) => {
return (element) => {
customElements.define(config.tagName, element, config.options);
}
}
export interface OnConnected {
connectedCallback(): void;
}
export interface OnDisconnected {
disconnectedCallback();
}
export interface OnAttributeChanged {
attributeChangedCallback(attrName?: string, oldVal?: string, newVal?: string);
}
export interface OnAdopted {
adoptedCallback();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment