chore(file-max-size): implemented destroy

This commit is contained in:
Johannes Eder 2021-07-20 11:17:16 +02:00 committed by Sarah Vaupel
parent 8cb3a41fcb
commit 1153ba8711
2 changed files with 13 additions and 1 deletions

View File

@ -57,6 +57,7 @@ export class FileInput {
}
destroy() {
this._eventManager.cleanUp();
this._fileList.remove();
this._label.remove();
this._element.classList.remove(FILE_INPUT_INITIALIZED_CLASS);

View File

@ -1,4 +1,5 @@
import { Utility } from '../../core/utility';
import { EventManager, EventWrapper, EVENT_TYPE } from '../../lib/event-manager/event-manager';
const FILE_MAX_SIZE_INITIALIZED_CLASS = 'file-max-size--initialized';
@ -9,6 +10,8 @@ export class FileMaxSize {
_element;
_app;
_eventManager;
constructor(element, app) {
if (!element)
throw new Error('FileMaxSize utility cannot be setup without an element!');
@ -16,6 +19,8 @@ export class FileMaxSize {
this._element = element;
this._app = app;
this._eventManager = new EventManager();
if (this._element.classList.contains(FILE_MAX_SIZE_INITIALIZED_CLASS)) {
throw new Error('FileMaxSize utility already initialized!');
}
@ -24,7 +29,13 @@ export class FileMaxSize {
}
start() {
this._element.addEventListener('change', this._change.bind(this));
const changeEv = new EventWrapper(EVENT_TYPE.CHANGE, this._change.bind(this), this._element);
this._eventManager.registerNewListener(changeEv);
}
destroy() {
this._eventManager.cleanUp();
this._element.classList.remove(FILE_MAX_SIZE_INITIALIZED_CLASS);
}
_change() {