Should {{render}} reuse controller instances?


#1

{{render}} is a great way to split your app up into logical MVC pieces, but it all falls apart when you have more than instance of the MVC.

It makes sense to reuse controllers that are coupled to routes, but a bad idea when using {{render}}.

Thoughts? Should {{render}} not reuse controllers? Why would I want this behavior over getting new instances like components? Is the answer to use components for everything except controllers associated with routes?

For example, this is terrible, two instances of {{render newItem}} share the controller and then cause a ton of problems:


#2

I’d file this in the same unadvisable category as having a LoginController that other controllers in your app specify as a needs dependency, while also having the LoginController drive a template (regardless of whether or not LoginController is a route-driven template).

While it’s sometimes expedient, I think it’s one of those places where Ember as a framework doesn’t make you feel enough pain for doing something bad.

I don’t know if we should explicitly forbid it, but I think I’d be in favor of an Ember.warn if you try and {{render}} a route-driven controller.


#3

Actually my response was somewhat premature (or at least addressed the wrong issue):

It seems fine to me that a {{render}} helper would reuse a controller as a default, but I think you’ll want something tied to a specific model rather than just {{render 'someTemplateAndController}}. It’s not perfect, but keep in mind that today you can do {{render 'someTemplateAndController' someModel}}, and this form will not reuse an existing controller but will create a new one for you.


#4

Realised my comment was a bit off-topic here, moved to a new thread, When to use components vs render


#5

hmm, this works as expected, I’ll need to dig into my app some more later to figure out what is going on:


#6

okay, I a dummy, I thought I was passing a model into my {{render}}s but I was not.

many apologies.