Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call Mixin method when overriding

Tags:

ember.js

I've got a Mixin in my controller that has a particular action. I need to override this action, do some stuff, and then call the original action provided by the Mixin.

How can I do this?

this._super() doesn't seem to work in this case (which does make sense, as it's meant to call the superclass' implementation, not a Mixin's).

like image 387
elsurudo Avatar asked Feb 09 '14 11:02

elsurudo


1 Answers

In order to call this._super from Ember.run.next try the following,

http://emberjs.jsbin.com/docig/3/edit

App.MyCustomMixin = Ember.Mixin.create({
  testFunc:function(){
    alert('original mixin testFunc');
  },
  actions:{
    testAction:function(){
      alert('original mixin testAction');
    }
  }
});

App.IndexController = Ember.Controller.extend(App.MyCustomMixin,{
  testFunc:function(){
    alert('overriden mixin testFunc');

    var orig_func = this._super;
    Ember.run.next(function(){
      orig_func();
    });
  },
  actions:{
    test:function(){
      this.testFunc();
    },
    testAction:function(){
      alert('overriden mixin testAction');
      var orig_func = this._super;
      Ember.run.next(function(){
        orig_func();
      });
    }
  }
});
like image 172
melc Avatar answered Nov 12 '22 20:11

melc