Famous/inputs — pull request #2 by danzaner (2014-04-15 23:51:50+00:00)
Title: Topic tap doubletap longpress

Dave Fetterman asked that I send this pull request through. He has my signed Contributor's doc.

I've written a feature to augment the payload generated by TouchSync so that it indicates whether the current touch is a completed "tap", a "double tap" or a touch that began as a "long press" (whether or not it moves after the long press). It leverages the history maintained by TouchTracker. There are three new constants in TouchTracker to determine the thresholds for the states.

Almost all of the code is an addition, so it should be very compatible. One thing to watch out for is that I altered the "touch" property of the payload. "touch" was being set to the touch's "identifier", not the touch itself. (Sort of misleading given the name and odd, so I wonder if it was done for some performance reason I don't understand.) I set it to the actual "touch" object, which of course, includes the identifier. I did this not because the gesture augmentations need it, but because code that triggers off the augmentations may need the entire "touch", and the "touch" is deleted from TouchTracker's history immediately after the "trackend" is emitted. That means "end" event handlers can't look up the touch by identifier in TouchTracker, so I included the full object in the payload. I included it in all TouchSync event payloads for consistency. Obviously, this could cause incompatibilities in other code, but the code would only have to reference the identifier in the object, which is a really minor fix.

If including the full "touch" is a performance issue, I'd suggest not deleting history objects on "trackend", but instead queuing them for deletion after, say, 10 touches. That way, code that needed the full touch object in an "end" handler would have time to look it up before it got deleted.

Hope you guys find my feature useful! Keep up the great work!

Best,
Dan Zaner
danzaner@gmail.com