I’m the author of the chriswessels:hammer package: https://atmospherejs.com/chriswessels/hammer
It adds the
Template.foo.gestures function which allows you to register an event map of callbacks (much like
Template.foo.events, but specifically for multi-touch gestures. It is powered by Hammer.js under the hood.
The first version created an instance of Hammer.js for each registered gesture and bound it to the DOM element in a data attribute (using the jQuery plugin for Hammer.js, which is quite clean).
I realised this wasn’t a great approach because Blaze could randomly replace the DOM element and thus the Hammer.js instance would be lost. I tried using the
onRendered) callback, but this didn’t seem to be triggered for every Blaze update, and the Hammer.js instance was still lost on occasion.
I then changed the structure of the plugin to create a single instance of Hammer.js on the body element (again, bound to the DOM element via a data attribute), and any gestures registered via the
Template.foo.gestures plugin were registered with that the body instance (by computing a ultra-specific selector string from the body element down to the specific element in the event map and doing a match check when a tracked gesture was triggered on the body instance). This was working fine, but with Meteor 1.1 it seems to have broken!
Given that the package seems to be the most popular for integrating and using Hammer.js, I want to fix it properly. I’m therefore after guidance on to how to architect the package internals so that it plays well with Blaze internals. I’m open to any/all changes!
I guess the ideal architecture would be a single instance of Hammer.js attached to each template instance that makes a call to
Template.foo.gestures, with the specific selectors in the event map being matched against in the callback (which then executes any matching callbacks specified). This seems like the right balance between memory usage and granularity of control.
The source code is here: https://github.com/chriswessels/meteor-hammer
Guidance anyone can provide would be much appreciated!