-
Notifications
You must be signed in to change notification settings - Fork 25
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
Unregister event handler #127
Conversation
Changes Unknown when pulling 4464ce9 on sophypal:fix-leak into ** on ciena-frost:master**. |
}, | ||
|
||
willDestroy () { | ||
$(document).off(`keyup.${this.elementId} keydown.${this.elementId}`, this.setShift.bind(this)) | ||
$(document).off(`keyup.${this.elementId} keydown.${this.elementId}`, this._keyHandler) |
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.
Any way to add a unit test for this? Like maybe stubbing out setShift.bind
to return something different in willDestroy
to make sure it's the instance from before that's passed into off
?
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.
Integration test added.
addon/components/frost-list.js
Outdated
if (!this.isDestroyed) { | ||
this.set('_isShiftDown', event.shiftKey) | ||
} | ||
run.next(() => { |
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.
Previously holding shift while the test would run would cause errors. This fixes that.
Changes Unknown when pulling afd94b6 on sophypal:fix-leak into ** on ciena-frost:master**. |
addon/components/frost-list.js
Outdated
this.set('_isShiftDown', event.shiftKey) | ||
} | ||
run.next(() => { | ||
if (!this.isDestroyed) { |
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.
You probably want:
if (this.isDestroyed || this.isDestroying) return
this.set('_isShiftDown', event.shiftKey)
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.
I don't think this.set
will cause errors if the component is being destroyed but I can update it.
@@ -150,11 +152,12 @@ export default Component.extend({ | |||
}) | |||
} | |||
|
|||
$(document).on(`keyup.${this.elementId} keydown.${this.elementId}`, this.setShift.bind(this)) | |||
this._keyHandler = this.setShift.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.
I'd personally prefer you name it this._keyUpHandler
to be more specific.
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.
Except that it's for both keyup
and keydown
events.
@@ -150,11 +152,12 @@ export default Component.extend({ | |||
}) | |||
} | |||
|
|||
$(document).on(`keyup.${this.elementId} keydown.${this.elementId}`, this.setShift.bind(this)) | |||
this._keyHandler = this.setShift.bind(this) | |||
$(document).on(`keyup.${this.elementId} keydown.${this.elementId}`, this._keyHandler) |
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.
I assume there are no scenarios in which the elementId
can change during a components life cycle? Otherwise this would be problematic as the .off()
could be for different events than .on()
.
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.
elementId
shouldn't change for the same component instance.
Changes Unknown when pulling 0b339ff on sophypal:fix-leak into ** on ciena-frost:master**. |
CHANGELOG
keyup/down
events.