Created
September 5, 2018 06:18
-
-
Save kepek/ae56ed39e0860d75b8ea4a365c99ff08 to your computer and use it in GitHub Desktop.
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 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