Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map multiple native events to a semantic application event in Ember.js?

I have not used Ember.js before, but after reading the part of the guide on views, I wanted to know how the Ember experts out there would handle a situation where multiple native events needed to be mapped to the same "application event".

In the guide, the example given shows mapping the (native) click event to the (application-specific) deleteItem event. In many cases, it is common for many native events to map to one application-specific event. What if a user was using a touch device that also had a keyboard and mouse attached (e.g. soon-to-come Windows 8 tablets), and I needed to map the "touchstart", "click" and "keyup" (e.g. [CTRL]-D) events to the same application-specific event like deleteItem?

Would you just put 3 methods on the view -- touchStart, click and KeyUp -- and have them all call a common 4th method to send the deleteItem event?

Is there anything built into Ember to handle this situation -- specifically, the situation where multiple native events all have the same semantic meaning in an app? I think this will become more and more common as browsers are touch enabled, laptops are touch-enabled and browser APIs can accept input from other hardware like mic, camera, etc... I could imagine a device where 5 or 6 native events all have the same semantic meaning for a given view.

Thanks!

like image 583
Johnathan Hebert Avatar asked Jan 22 '26 13:01

Johnathan Hebert


1 Answers

We've been talking about something similar to support 'tap' events.

I think the best approach is to use register jQuery 'special events'. Here's a link to more information: http://benalman.com/news/2010/03/jquery-special-events/

To make a special event work with Ember views, you'll need to register it as a custom event on your Ember.Application instance:

Ember.Application.create({
  customEvents: {
    // key is the jquery event, value is the name used in views
    myeventname: 'myEventName'
  }
});
like image 144
ebryn Avatar answered Jan 25 '26 02:01

ebryn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!