Skip to content
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

fix missing bind on mouse events listener #315

Merged
merged 4 commits into from
Feb 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions addon/components/flash-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@ export default Component.extend({
set(this, 'active', true);
});
set(this, 'pendingSet', pendingSet);
this.element.addEventListener('mouseenter', this._mouseEnter);
this.element.addEventListener('mouseleave', this._mouseLeave);
this.set('_mouseEnterHandler', this._mouseEnter.bind(this));
this.set('_mouseLeaveHandler', this._mouseLeave.bind(this));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we approach with 1 format here instead of having a this.set and set(this, ...) mixed in code? In fact it would be nicer to use Ember.setProperties(this, {}). Thoughts? @Turbo87 @sbatson5

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since _mouseEnterHandler is never observed in the template you can also just use this._mouseEnter = this._mouseEnter.bind(this); to simplify it a little bit

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd lean toward Ember.set since that's the convention used elsewhere.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sbatson5 I'm confused: you 👍ed @Turbo87's suggestion and proposed another alternative. Which one would you like to be implemented?

Copy link
Collaborator

@sbatson5 sbatson5 Feb 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dcyriller Sorry for the confusion. I was 👍ing the suggestion that this.foo = x is possible rather than this.set('foo', x). However, given that that this repo is still using Ember.set('foo', x) everywhere, I would lean toward Ember.set.

this.element.addEventListener('mouseenter', this._mouseEnterHandler);
this.element.addEventListener('mouseleave', this._mouseLeaveHandler);
},

willDestroyElement() {
this._super(...arguments);
this.element.removeEventListener('mouseenter', this._mouseEnter);
this.element.removeEventListener('mouseleave', this._mouseLeave);
this.element.removeEventListener('mouseenter', this._mouseEnterHandler);
this.element.removeEventListener('mouseleave', this._mouseLeaveHandler);
},

progressDuration: computed('flash.showProgress', {
Expand Down