Skip to content

Instantly share code, notes, and snippets.

@tvandervossen
Created November 4, 2011 10:25
Show Gist options
  • Select an option

  • Save tvandervossen/1339061 to your computer and use it in GitHub Desktop.

Select an option

Save tvandervossen/1339061 to your computer and use it in GitHub Desktop.
Callback or custom event?
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?
@flurin

flurin commented Nov 4, 2011

Copy link
Copy Markdown

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.

@pawelkomarnicki

Copy link
Copy Markdown

Event, feels right

@stravid

stravid commented Nov 4, 2011

Copy link
Copy Markdown

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.

@flurin

flurin commented Nov 4, 2011

Copy link
Copy Markdown

@stravid, indeed: decoupling like this is easier to manage in the end.

@mislav

mislav commented Nov 4, 2011

Copy link
Copy Markdown

Check out touch.js and gesture.js of Zepto

@tvandervossen

Copy link
Copy Markdown
Author

@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