I’ve recently been asked how to deal with touch events in DukeScript. One option is
the most important number of events and gestures. You could create an API for that and wrap
the events in Java Events, but it’s much more elegant to stay in the knockout world.
We don’t need to pollute our viewmodels with the notion of events, we can still use declarative
bindings by simply registering knockout bindings for the hammer events. I used knockout-hammer
as starting point, but I had to modify it a bit to get it to work:
module of my DukeScript project (because the POM of this module has some special
When calling KnockoutHammer.init(), HammerLibrary.init() is
The actual event is prefixed with “hm”, so it’s “hmTap”. The name of the handler function is “onHmTap”.
We can also pass some constraints. In our case we collect all the taps that happen in a 500ms interval.
Now let’s have a look at the function that is called on our viewmodel:
DukeScript recognizes the “tapCount” property of the method signature and automatically extracts the matching value from the event.
Now launch the application on your Android or iOS device and check the result.
If successful I suggest doing a little victory dance to this tune.