chore(async-form): implemented destroy method in async-form
This commit is contained in:
parent
a25b59b318
commit
e2aa913ff3
@ -5,6 +5,7 @@ export const EVENT_TYPE = {
|
||||
INVALID : 'invalid',
|
||||
CHANGE : 'change',
|
||||
MOUSE_OVER : 'mouseover',
|
||||
SUBMIT : 'submit',
|
||||
//more to be added
|
||||
};
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { Utility } from '../../core/utility';
|
||||
import { Datepicker } from '../form/datepicker';
|
||||
import { EventManager, EventWrapper, EVENT_TYPE } from '../../lib/event-manager/event-manager';
|
||||
import './async-form.sass';
|
||||
|
||||
const ASYNC_FORM_INITIALIZED_CLASS = 'check-all--initialized';
|
||||
@ -20,6 +21,8 @@ export class AsyncForm {
|
||||
_element;
|
||||
_app;
|
||||
|
||||
_eventManager;
|
||||
|
||||
constructor(element, app) {
|
||||
if (!element) {
|
||||
throw new Error('Async Form Utility cannot be setup without an element!');
|
||||
@ -28,17 +31,23 @@ export class AsyncForm {
|
||||
this._element = element;
|
||||
this._app = app;
|
||||
|
||||
this._eventManager = new EventManager();
|
||||
|
||||
if (this._element.classList.contains(ASYNC_FORM_INITIALIZED_CLASS)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._element.addEventListener('submit', this._submitHandler);
|
||||
const submitEvent = new EventWrapper(EVENT_TYPE.SUBMIT, this._submitHandler.bind(this), this._element);
|
||||
this._eventManager.registerNewListener(submitEvent);
|
||||
|
||||
this._element.classList.add(ASYNC_FORM_INITIALIZED_CLASS);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
// TODO
|
||||
this._eventManager.removeAllEventListenersFromUtil();
|
||||
|
||||
if(this._element.classList.contains(ASYNC_FORM_INITIALIZED_CLASS))
|
||||
this._element.classList.remove(ASYNC_FORM_INITIALIZED_CLASS);
|
||||
}
|
||||
|
||||
_processResponse(response) {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { AsyncForm } from './async-form';
|
||||
import { AsyncForm, ASYNC_FORM_INITIALIZED_CLASS } from './async-form';
|
||||
|
||||
describe('AsyncForm', () => {
|
||||
|
||||
@ -13,6 +13,12 @@ describe('AsyncForm', () => {
|
||||
expect(asyncForm).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should destroy asyncForm', () => {
|
||||
asyncForm.destroy();
|
||||
expect(asyncForm._eventManager._registeredListeners.length).toBe(0);
|
||||
expect(asyncForm._element.classList).not.toContain(ASYNC_FORM_INITIALIZED_CLASS);
|
||||
});
|
||||
|
||||
it('should throw if called without an element', () => {
|
||||
expect(() => {
|
||||
new AsyncForm();
|
||||
|
||||
Reference in New Issue
Block a user