O'Reilly logo

Mastering Ember.js by Mitchel Kelonye

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Event subscription

Another way of notifying changes in an application is through event subscription. This paradigm is used heavily in Node.js to channel messages and events across different components of an application. Ember.js provides the Ember.Evented mixin that can be used to serve archive this easily. For example, blocks in a board game can subscribe to instructions from an actuator as in the following example:

var GRID_SIZE = 4; 
var actuator = Em.Object.createWithMixins(Em.Evented);

var block = Em.Object.createWithMixins(Em.Evented);
acuator.on('moveRight', function(){
  var x = block.get('x') + 1;
  x = x % GRID_SIZE; 
  block.set('x', x);
});

actuator.trigger('moveRight');

The mixin provides five essential methods, two of which have been illustrated ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required