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

Unregister event handler #127

Merged
merged 3 commits into from
Apr 6, 2017
Merged

Unregister event handler #127

merged 3 commits into from
Apr 6, 2017

Conversation

sophypal
Copy link
Contributor

@sophypal sophypal commented Apr 6, 2017

  • #none# - documentation fixes and/or test additions
  • #patch# - backwards-compatible bug fix
  • #minor# - adding functionality in a backwards-compatible manner
  • #major# - incompatible API change

CHANGELOG

  • Fixed memory leak by removing the original event handler for keyup/down events.

@coveralls
Copy link

Coverage Status

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)
Copy link

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Integration test added.

if (!this.isDestroyed) {
this.set('_isShiftDown', event.shiftKey)
}
run.next(() => {
Copy link
Contributor Author

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.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling afd94b6 on sophypal:fix-leak into ** on ciena-frost:master**.

this.set('_isShiftDown', event.shiftKey)
}
run.next(() => {
if (!this.isDestroyed) {
Copy link
Contributor

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)

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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().

Copy link
Contributor Author

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.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 0b339ff on sophypal:fix-leak into ** on ciena-frost:master**.

@sandersky
Copy link
Contributor

sandersky commented Apr 6, 2017

👍

Approved with PullApprove

@sandersky sandersky merged commit 737b0c3 into ciena-frost:master Apr 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants