Tom
Tom

Reputation: 119

Ember View Inheritance Questions

I am implementing this view logic inheritance into EmberJ and I would like to ask two questions.

App.MyBaseView = Ember.View.extend({
  didInsertElement: function(){
    // shared logic
  }.on('didInsertElement')
});

App.FirstSpecificView = App.MyBaseView.extend({

  didInsertElement: function(){
    // this views specific logic
  }.on('didInsertElement')
});

App.SecondSpecificView = App.MyBaseView.extend({

  didInsertElement: function(){
    // this views specific logic
  }.on('didInsertElement')
});

What is the use of ".on(didInsertElement)"?

How does the use of "onDidInsert" and "didInsertElement" differ?

Upvotes: 0

Views: 67

Answers (1)

Imp
Imp

Reputation: 151

I'm not that proficient with Ember JS, and just work with it for 3 months now, but first of all... I've never seen such syntax. I mean:

App.MyBaseView = Ember.View.extend({
  didInsertElement: function(){
    // shared logic
  }.on('didInsertElement')  //this :D
});

There is no need for this 'on('eventName')'. You just simply add function handle to the property and that's all. So it would be like:

App.MyBaseView = Ember.View.extend({
  didInsertElement: function(){
    // shared logic
  }
});

Nonetheless I assume you would like to call method from the superclass in the subclass. Then use it like that:

  App.MyBaseView = Ember.View.extend({
  didInsertElement: function(){
    // shared logic
  }
});

App.FirstSpecificView = App.MyBaseView.extend({    
  didInsertElement: function(){
    this._super();  //this should call superclass method
    // this views specific logic
  }
});

App.SecondSpecificView = App.MyBaseView.extend({  
  didInsertElement: function(){
    this._super();    //this should call superclass method
    // this views specific logic
  }
});

Upvotes: 2

Related Questions