Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ember ATX: Ember.Evented

Ember ATX: Ember.Evented

Lightning talk about one of my favorite Ember mixins, Ember.Evented!

timgthomas

July 24, 2015
Tweet

More Decks by timgthomas

Other Decks in Technology

Transcript

  1. Hi!

  2. // models/item.js export default Ember.Object.extend({ actions: { save() { this.set('savedAt',

    new Date()); } } }); // components/show-item.js export default Ember.Component.extend({ itemSaved: function() { // ... }.observes('item.savedAt') });
  3. // models/item.js export default Ember.Object.extend(Ember.Evented, { actions: { save() {

    this.trigger('saved'); } } }); // components/show-item.js export default Ember.Component.extend({ init() { this._super(); this.get('item').on('saved', this.itemSaved); } });
  4. // controllers/list.js export default Ember.Controller.extend(Ember.Evented, { actions: { save() {

    this.trigger('saved'); } } }); // controllers/item.js export default Ember.Controller.extend({ init() { this._super(); this.get('controllers.list').on('saved', () => {}); } });
  5. let controller = this.get('controllers.foo'); controller.trigger('foo'); controller.trigger('foo', 'bar'); controller.on('foo', () =>

    {}); controller.off('foo', () => {}); controller.one('foo', () => {}); controller.has('foo');