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