Skip to content
This repository has been archived by the owner on Dec 26, 2018. It is now read-only.

hammers destroy() is never being called #103

Open
codeabilly opened this issue Oct 25, 2017 · 0 comments
Open

hammers destroy() is never being called #103

codeabilly opened this issue Oct 25, 2017 · 0 comments

Comments

@codeabilly
Copy link

There's a part of code in your unbind hook that's never being called

Here's entire block of code.

unbind: function () {
    if (this.handler) {
        this.mc.off(this.arg, this.handler)
    }
    if (!Object.keys(this.mc.handlers).length) {
        this.mc.destroy()
        this.el.hammer = null
    }
}

this.mc.handlers is Object having each handler bound in key : [value] fassion

this.mc.off(this.arg, this.handler) does not remove handler from this object, instead it sets its value to empty array.

That would mean that following lines:

if (!Object.keys(this.mc.handlers).length) {
    this.mc.destroy()
    this.el.hammer = null
}

Never gets called since !Object.keys(this.mc.handlers).length always remain the same and that is total number of handlers that were bound to an element in the first place.

Better way to do it would be:

var handlers = this.mc.handlers
if (!Object.keys(handlers).filter(h => handlers[h].length).length) {
    this.mc.destroy()
    this.el.hammer = null
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant