Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ember: best way to reuse controller actions on mixins

Tags:

ember.js

Example jsbin: http://jsbin.com/ICoLOgO/4/edit

If I have a mixin that provides an action, with ember 1.0-rc.5 the action would be invoked without warnings. Upgrading to ember 1.0 final causes a deprecation warning to show:

Action handlers implemented directly on controllers are deprecated in favor of action handlers on an `actions` object

Is there a simpler way to expose individual actions in an action map without needing to use function.apply?

like image 282
Chris Eldredge Avatar asked Oct 17 '13 16:10

Chris Eldredge


1 Answers

I just put the common actions in the actions hash on the mixin, and Ember took care of properly merging the actions hashes with any controllers that extend the mixin.

App.PaginatedListController = Ember.Mixin.create({
  queryParams: ['page'],
  page: 0,

  actions: {
    nextPage: function() {
      this.incrementProperty('page');
    },

    previousPage: function() {
      this.decrementProperty('page');
    },
  }
});

App.PostsController = Ember.ArrayController.extend(App.PaginatedListController, {
  actions: {
    // controller specific actions here
  }
});
like image 127
kturney Avatar answered Nov 11 '22 14:11

kturney