Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route view is initialized when model changes #4353

Closed
zaius opened this issue Feb 12, 2014 · 9 comments
Closed

Route view is initialized when model changes #4353

zaius opened this issue Feb 12, 2014 · 9 comments

Comments

@zaius
Copy link

zaius commented Feb 12, 2014

I've noticed that a route's view is initialized every time the model changes on a route, even though the model is actually rendered into the original view.

Here's a quick jsbin:
http://jsbin.com/ucanam/3732/edit

Is there any reason for the view to be created (and then not used)? Or should I try and find where in the router this is happening?

@machty
Copy link
Contributor

machty commented Feb 12, 2014

/cc @ef4 ... this seems related to the optimization to not re-render between route transitions if only the models (and not the route hierarchy) has changed.

@ef4
Copy link
Contributor

ef4 commented Feb 12, 2014

Yes, it's intentional that a new View object gets instantiated. See the code changes in #2593.

The reason for this is that the view gets to pick what template and context it wants to render with, so we can't tell if the template and context are unchanged until after instantiating the view.

The only way to avoid creating this "unused" view object would be to change the view API so that views can no longer dynamically override those things, which is probably not worth it.

@machty
Copy link
Contributor

machty commented Feb 12, 2014

Thanks @ef4. Seems intentional and not likely to change any time soon, so closing.

@machty machty closed this as completed Feb 12, 2014
@stefanpenner
Copy link
Member

I think we should strongly consider if we can take another approach that prevents this view from needing to be instantiated, while preserving @ef4's optimization.

@stefanpenner stefanpenner reopened this Feb 12, 2014
@machty
Copy link
Contributor

machty commented Feb 12, 2014

Seems to be a common theme :) walking the prototype, anyone?

@stefanpenner
Copy link
Member

no, i think there exists a path were we defer actual creation of views till much much later, merely passing the view factory around till the very last moment. This will likely sort out, or enable sorting out several other quirks

@zaius
Copy link
Author

zaius commented Feb 13, 2014

Hmm ok. I'm still learning the ember code base, and I'm trying to wrap my head around changing a view's template / context on a model change. Is there a specific use case or an example jsbin or something that can help me get a better idea of how / why you'd do that?

If I was doing something like that, I would expect to have to override renderTemplate in the route. If enforcing that is an acceptable solution, then the equality check of the views could be moved up into the route's render method.

@wagenet
Copy link
Member

wagenet commented Apr 2, 2014

@stefanpenner what's the next step on this?

@wagenet
Copy link
Member

wagenet commented Jul 28, 2014

See #5264

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants