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

Destroy function removeEventListener looks wrong #21

Closed
bruce-one opened this issue Jul 12, 2016 · 1 comment · Fixed by #22
Closed

Destroy function removeEventListener looks wrong #21

bruce-one opened this issue Jul 12, 2016 · 1 comment · Fixed by #22
Labels

Comments

@bruce-one
Copy link
Contributor

To my eye, it looks like the removeEventListeners in destroy are incorrect. Here.

(AFAIU):

The result of owner.onChange.bind(owner) is a new function, hence the removal is trying to remove a "different" function to the one that's attached, and hence not removing anything. Instead the result of the bind could be stored as a variable so that the exact save function is passed to removeEventListener, and hence is removed correctly.

To try and demonstrate:

Object.keys(getEventListeners(document.body)).length
> 0
func1 = () => console.log('a')
> () => console.log('a')
document.body.addEventListener('click', func1.bind(document))
> undefined
Object.keys(getEventListeners(document.body)).length
> 1
document.body.removeEventListener('click', func1.bind(document))
> undefined
Object.keys(getEventListeners(document.body)).length
> 1

vs

Object.keys(getEventListeners(document.body)).length
> 0
func1 = () => console.log('a')
> () => console.log('a')
bound = func1.bind(document)
> () => console.log('a')
document.body.addEventListener('click', bound)
> undefined
Object.keys(getEventListeners(document.body)).length
> 1
document.body.removeEventListener('click', bound)
> undefined
Object.keys(getEventListeners(document.body)).length
> 0

(Apologies if I'm being silly :-) (I haven't actually tried the library, I just noticed it... It looks neat though, awesome work, and I love the idea :-) ))

@nosir
Copy link
Owner

nosir commented Jul 12, 2016

Oh, hmm, thanks for the PR, will test it a bit and merge.

@nosir nosir added the bug label Jul 13, 2016
@nosir nosir closed this as completed in #22 Jul 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants