Skip to content

Instantly share code, notes, and snippets.

@kepek
Created September 5, 2018 08:36
Show Gist options
  • Save kepek/970b7d32db45b64dd0139dd1d186f855 to your computer and use it in GitHub Desktop.
Save kepek/970b7d32db45b64dd0139dd1d186f855 to your computer and use it in GitHub Desktop.
export interface IStringTMap<T> {
[key: string]: T;
}
export class COptions<TProperties> {
constructor(properties?: TProperties) {
if (properties) {
for (let propertyName in properties) {
if (properties.hasOwnProperty(propertyName)) {
Object.defineProperty(this, propertyName, {
value: properties[propertyName],
writable: true,
enumerable: true
});
}
}
}
}
}
export default class CComponent<
TElement extends Element,
TOptions extends Object
> {
protected element: TElement | NodeListOf<TElement> | null;
protected options: TOptions;
constructor(
element: TElement | NodeListOf<TElement> | null,
options?: TOptions
) {
this.element = element;
this.options = Object.assign({}, options);
if (!this.element) {
return;
}
if (this.element instanceof NodeList) {
Array.from(this.element).forEach(element => {
this.initialize(element, this.options);
});
} else if (this.element instanceof HTMLElement) {
this.initialize(this.element, this.options);
}
}
initialize(element: TElement, options: TOptions): any {
return {
element,
options
};
}
}
export class Kepek extends CComponent<Element, Object> {
protected canvas: HTMLCanvasElement | undefined;
initialize(element: Element, options: Object): Object {
return {
element,
options
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment