What happened to didInsertElement in the component API documentation?


What happened to the component lifecycle hooks in the API documentation? It is clearly referenced in the v2.4 guide, but not in the API docs.

https://guides.emberjs.com/v2.4.0/components/the-component-lifecycle/ http://emberjs.com/api/classes/Ember.Component.html

I was confused about the guide showing a this.super() call on a didInsertElement example, and went to go look up the API docs, but was surprised to find it missing. Not even under deprecated.


And since when is it required to call this._super() in didInsertElement?


didInsertElement only appears under http://emberjs.com/api/classes/Ember.ViewTargetActionSupport.html

which is a mixin that Ember.Component uses.


What I’ve learned is that when overriding/extending methods, you should call this._super(...arguments) as best practice.

See http://poteto.github.io/component-best-practices/#/super


@Guarav: You’re right - I see it in the code, however it seems that the documentation does not reflect this in the inherited properties.

@rmmpaderes: After a little digging, it appears that the base class defines didInsertElement as follows:

didInsertElement: K,

where K is simply the identity function (return this), so calling this._super() in didInsertElement seems superfluous, as there is no default behavior upon insertion of the element. The only justification I can imagine for continuing to do so is in the case that a default behaviour is introduced in the future.



Yes that’s the reason why it’s best practice to use super, in case that a default behavior is introduced in the future (which I don’t think it will, but you never know :wink:).

Another example is if you have a mixin that implements didInsertElement() inside the component. So in order to execute the didInsertElement() of the component before running the one in the mixin, you use super. If however, you’re absolutely sure that it will never happen then feel free to not omit. But again, with the first reason above, it should be sufficient to convince you to use it as best practice.


Thanks to Gaurav’s PR here: https://github.com/emberjs/ember.js/pull/13237 this is now in the API docs. In the future, if you notice things like this, opening an issue is much appreciated! :wink: