Updated

JavaScript Classes

A unified way to create class based compoments.

const SELECTORS = {};

const CLASSES = {};

export class ${COMPONENT_NAME} {
constructor() {
// TODO: Get required elements

const requiredElements = [];

if (requiredElements.some((el) => !el)) {
// throw new Error('${COMPONENT_NAME} not initialized');
// or
return;
}

this.bindEvents();
this.setup();
}

static init() {
// eslint-disable-next-line no-unused-vars
const ${COMPONENT_NAME.toLowerCase()} = new ${COMPONENT_NAME}();
}

/**
* Bind `this` explicitly for event listeners.
*/

bindEvents() {
[
/* TODO: Add all names of event listeners*/
].forEach((e) => {
this[e] = this[e].bind(this);
});
}

/**
* Setup all event listeners used by the component.
*/

setupEventListeners() {}

setup() {
this.setupEventListeners();
}

/**
* Remove all event listeners and dependancies.
*/

destroy() {}
}
Made with ❤ in Neopix HQ