chore(reactive-submit-button): implemented destroy

This commit is contained in:
Johannes Eder 2021-07-13 12:41:44 +02:00 committed by Sarah Vaupel
parent 2f668c1d3e
commit db30fa6423

View File

@ -1,4 +1,5 @@
import { Utility } from '../../core/utility';
import { EventManager, EventWrapper, EVENT_TYPE } from '../../lib/event-manager/event-manager';
const REACTIVE_SUBMIT_BUTTON_INITIALIZED_CLASS = 'reactive-submit-button--initialized';
@ -12,12 +13,15 @@ export class ReactiveSubmitButton {
_requiredInputs;
_submitButton;
_eventManager;
constructor(element) {
if (!element) {
throw new Error('Reactive Submit Button utility cannot be setup without an element!');
}
this._element = element;
this._eventManager = new EventManager();
if (this._element.classList.contains(REACTIVE_SUBMIT_BUTTON_INITIALIZED_CLASS)) {
return false;
@ -51,16 +55,18 @@ export class ReactiveSubmitButton {
}
destroy() {
// TODO
this._eventManager.removeAllEventListenersFromUtil();
this._element.classList.remove(REACTIVE_SUBMIT_BUTTON_INITIALIZED_CLASS);
}
setupInputs() {
this._requiredInputs.forEach((el) => {
const checkbox = el.getAttribute('type') === 'checkbox';
const eventType = checkbox ? 'change' : 'input';
el.addEventListener(eventType, () => {
const eventType = checkbox ? EVENT_TYPE.CHANGE : EVENT_TYPE.INPUT;
const valEvent = new EventWrapper(eventType,(() => {
this.updateButtonState();
});
}).bind(this), el );
this._eventManager.registerNewListener(valEvent);
});
}