Created
November 4, 2011 10:25
-
-
Save tvandervossen/1339061 to your computer and use it in GitHub Desktop.
Callback or custom event?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hey, I’m playing around with a multitouch gesture recognition API | |
for Mobile Safari. Now I’m wondering; would you prefer to define the | |
event handler in a callback, like this: | |
recognize.tap(element, function() { | |
log('Tapped'); | |
}); | |
Or would you prefer the recognizer to fire a custom event, like this: | |
recognize.tap(element); | |
element.bind('tap', function() { | |
log('Tapped'); | |
}); | |
Which one do you like best? Why? |
I think firing an event is more "natural" as it fit's better with current models (tap is something that "happens" just like "click"). Also keeping track of event handlers is mostly done for you, with custom callbacks that's harder.
Event, feels right
Version 2. This way I can setup all my tap-able elements in my setup code and then bind / unbind my event handlers whenever I want without having the "recognize" module around.
@stravid, indeed: decoupling like this is easier to manage in the end.
Check out touch.js and gesture.js of Zepto
@mislav I’m familiar with Zepto but for anything but trivial multitouch support you can’t get away from having to define gesture recognizers.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Event. Consistency.