-
-
Notifications
You must be signed in to change notification settings - Fork 356
[Dropzone] Remove event listeners on disconnect #1951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -3,10 +3,16 @@ import { Controller } from '@hotwired/stimulus'; | |||
class default_1 extends Controller { | |||
connect() { | |||
this.clear(); | |||
this.previewClearButtonTarget.addEventListener('click', () => this.clear()); | |||
this.inputTarget.addEventListener('change', (event) => this.onInputChange(event)); | |||
this.clear = this.clear.bind(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it better to bind in initialize
stage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes, didn't think about that!
I'm never binding in connect and always use properties.
class A {
connect() {
someElement.addEventListener('click', this._click);
}
_click = (event) => {
…
};
@aleho, is the failing translator test related to this change? |
@kbond Afaik that's related to the bug introduced by a change to the string component (breaking various parts of Symfony and the UX demos too). (#1950 and symfony/symfony#57612) |
Good catch, thanks Alexander. |
Thank you @kbond! |
Events added in controller connect were not removed on disconnect. This would lead to events being triggered twice if a dropzone input is, e.g., moved in the DOM.