Last active
November 4, 2016 12:19
-
-
Save deebloo/f31920d0d19906a8b0003398f858607b to your computer and use it in GitHub Desktop.
Typescript declarations and decorators for custom elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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