Skip to content

Commit 88e75a2

Browse files
Joren BroekemaAnton Kot
andcommitted
fix(field): teardown registrarmanager listener on field after register
Co-authored-by: Anton Kot <anton.kot@ing.nl>
1 parent 8237b64 commit 88e75a2

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

packages/field/src/FormRegisteringMixin.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ export const FormRegisteringMixin = dedupeMixin(
1313
superclass =>
1414
// eslint-disable-next-line no-shadow, no-unused-vars
1515
class FormRegisteringMixin extends superclass {
16+
constructor() {
17+
super();
18+
this.__boundDispatchRegistration = this._dispatchRegistration.bind(this);
19+
}
20+
1621
connectedCallback() {
1722
if (super.connectedCallback) {
1823
super.connectedCallback();
@@ -31,9 +36,10 @@ export const FormRegisteringMixin = dedupeMixin(
3136
if (formRegistrarManager.ready) {
3237
this._dispatchRegistration();
3338
} else {
34-
formRegistrarManager.addEventListener('all-forms-open-for-registration', () => {
35-
this._dispatchRegistration();
36-
});
39+
formRegistrarManager.addEventListener(
40+
'all-forms-open-for-registration',
41+
this.__boundDispatchRegistration,
42+
);
3743
}
3844
}
3945

@@ -44,6 +50,10 @@ export const FormRegisteringMixin = dedupeMixin(
4450
bubbles: true,
4551
}),
4652
);
53+
formRegistrarManager.removeEventListener(
54+
'all-forms-open-for-registration',
55+
this.__boundDispatchRegistration,
56+
);
4757
}
4858

4959
_unregisterFormElement() {

0 commit comments

Comments
 (0)