fix(field): teardown registrarmanager listener on field after register

Co-authored-by: Anton Kot <anton.kot@ing.nl>
This commit is contained in:
Joren Broekema 2019-10-25 11:35:23 +02:00
parent 8237b64a3b
commit 88e75a271f

View file

@ -13,6 +13,11 @@ export const FormRegisteringMixin = dedupeMixin(
superclass =>
// eslint-disable-next-line no-shadow, no-unused-vars
class FormRegisteringMixin extends superclass {
constructor() {
super();
this.__boundDispatchRegistration = this._dispatchRegistration.bind(this);
}
connectedCallback() {
if (super.connectedCallback) {
super.connectedCallback();
@ -31,9 +36,10 @@ export const FormRegisteringMixin = dedupeMixin(
if (formRegistrarManager.ready) {
this._dispatchRegistration();
} else {
formRegistrarManager.addEventListener('all-forms-open-for-registration', () => {
this._dispatchRegistration();
});
formRegistrarManager.addEventListener(
'all-forms-open-for-registration',
this.__boundDispatchRegistration,
);
}
}
@ -44,6 +50,10 @@ export const FormRegisteringMixin = dedupeMixin(
bubbles: true,
}),
);
formRegistrarManager.removeEventListener(
'all-forms-open-for-registration',
this.__boundDispatchRegistration,
);
}
_unregisterFormElement() {