From 88e75a271feb8249e0c52e3729aa7dc6a7b57604 Mon Sep 17 00:00:00 2001 From: Joren Broekema Date: Fri, 25 Oct 2019 11:35:23 +0200 Subject: [PATCH] fix(field): teardown registrarmanager listener on field after register Co-authored-by: Anton Kot --- packages/field/src/FormRegisteringMixin.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/field/src/FormRegisteringMixin.js b/packages/field/src/FormRegisteringMixin.js index 700cf2a7d..b8277d456 100644 --- a/packages/field/src/FormRegisteringMixin.js +++ b/packages/field/src/FormRegisteringMixin.js @@ -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() {