Crabar
Crabar

Reputation: 1857

Using hook in component

I have a component where I'm using didInsertElement function. I need to make some changes in component based on its width and height. Now it works fine but I get many warnings about performance issues.

I read about new hooks (from 1.13): didReceiveAttrs for example. I tried to use it but got error on following ($() = null):

var recipeBoxHeight = this.$().find(".recipe-box").height();
var tagsHeight = this.$().find("#tags").height();
var recipeNameHeight = this.$().find(".recipe-name-text").height();

Is it possible to get these properties without warnings about performance problems?

Upvotes: 0

Views: 57

Answers (1)

Bek
Bek

Reputation: 3207

wrap them in Ember.run.schedule('afterRender',...) so your code gets executed in afterRender queue of run loop

didInsertElement() {
  this._super(...arguments);
  Ember.run.schedule('afterRender', this, function() {
   var recipeBoxHeight = this.$().find(".recipe-box").height();
   var tagsHeight = this.$().find("#tags").height();
   var recipeNameHeight = this.$().find(".recipe-name-text").height();
  });
}

Upvotes: 1

Related Questions