ccampbell / gator

Event delegation in Javascript
http://craig.is/riding/gators
492 stars 46 forks source link

Check handlers exist before attempting to remove them #5

Closed townxelliot closed 11 years ago

townxelliot commented 11 years ago

Allow off('event', 'selector') or off('event') to be called before any handlers have been added for a particular event or event/selector combination.

NB I haven't added a minifed version of the library as I'm not sure what your preferred minifier is.

ccampbell commented 11 years ago

Hey, thanks for this. After taking a closer look I realized there was more broken about this than just what you had fixed here.

I had to update _bind as well cause otherwise calling off before events were bound was causing the events to get bound twice when on was called.

https://github.com/ccampbell/gator/compare/7ab1b4dc83...c942d0ce68

Also curiously enough keeping the longer variables _handlers[gator.id][event][selector] instead of setting to a handlers variable actually is smaller after gzip.

townxelliot commented 11 years ago

Nice, thanks for incorporating. Interesting about the gzip. I use this in a context where we can't gzip (resources are on the client already), but I didn't check the effect on minification (I just assumed less js and fewer property lookups are "better" in a vague way).