Skip to content

Instantly share code, notes, and snippets.

@kepek
Created September 5, 2018 06:18
Show Gist options
  • Save kepek/ae56ed39e0860d75b8ea4a365c99ff08 to your computer and use it in GitHub Desktop.
Save kepek/ae56ed39e0860d75b8ea4a365c99ff08 to your computer and use it in GitHub Desktop.
export default class CComponent<
TElements extends Element,
TOptions extends Object
> {
private elements: TElements | NodeListOf<TElements> | null;
private options: TOptions;
constructor(
elements: TElements | NodeListOf<TElements> | null,
options?: TOptions
) {
this.elements = elements;
this.options = Object.assign({}, options);
if (!this.elements) {
return;
}
if (this.elements instanceof NodeList) {
Array.from(this.elements).forEach(element => {
this.initialize(element, this.options);
});
} else if (this.elements instanceof HTMLElement) {
this.initialize(this.elements, this.options);
}
}
private initialize(element: TElements, options: TOptions) {
return {
element,
options
};
}
}
export class MyComponent extends CComponent<Element, {}> {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment