View instances created then destroyed on route transition


#1

I have run into an interesting issue that I am not sure is a bug or intentional behavior regarding view creation/rendering/destroying on route/model changes.

When I hit a route, a view is created and rendered. It has the id “ember1.” When the model changes (imagine switching to a new persons profile, causing a model change), a new view is created with id “ember2.” Then, after some time (less than a second), our ember2 view is destroyed and the page is updated. From what I can tell, a new view is created and thrown away then the old view is reused.

Is this intentional behavior? If so, I can work with it, but I want to make sure since its rather confusing.

Relevant information:

In the JSBin, clicking a color causes a transition which just changes the simple “model.” I’m pushing the view information to the page (ids).


#2

@omarestrella A new App.IndexColorView instance created, but that will not be inserted into DOM. Add didInsertElement hook, it will be invoked once.

Ember.Route creates a new instance and compares the new instance with exiting one and [destroys] (https://github.com/emberjs/ember.js/blob/v1.5.1/packages/ember-routing/lib/ext/view.js#L55) it.


#3

This is what I was looking for but couldn’t find! Thanks @manoit88.

Now that I actually know that part of the view lifecycle, I can work with that.