Repository navigation
Description
I'm creating a single page application and I've decided on Ember.js. I'm investigating the new router, however, I think there are a bad design decision; singletons.
As far as I can tell, the idea is that the View is bound (data) to the Controller and events (actions) to the Router.
application.initialize(router) will create a singleton instance of each controller, and that singleton will be used whenever the controller is needed.
My problems:
-
I'm planning a big application, and I want it easy to maintain. Requirejs will be heavily used. Currently, this is my connectOutlets:
connectOutlets: function (router) { require(["app/trapeze/user"], function () { router.set("loginController", app.LoginController.create()); router.get("loginController").setProperties({ target: router, controllers: router, namespace: app }); router.get("applicationController").connectOutlet("login"); }); }
Since the loginController singleton is created way earlier (somewhere between 1 ms and 10 years :) ) in app.initialize() I have to manually create it myself, and that doesn't feel good.. :)
-
What about nesting? In another Route I've tried this:
router.get("loginController").connectOutlet("login");
I didn't expect it to work, and it didn't :)
Uncaught RangeError: Maximum call stack size exceeded
beforeKey
xformBefore
invokeAction
iterateSet
sendEvent
notifyObservers
Ember.notifyBeforeObservers
propertyWillChange
Ember.View.Ember.Object.extend._elementWillChange
Ember.View.Ember.Object.extend.forEachChildView
Ember.View.Ember.Object.extend._elementWillChange
and then it repeats
I like the movement away from singletons, but this is a problem (it's a problem that there are singletons, not the idea of moving away from singletons), any ideas or comments?
Activity
trek commentedon Jul 3, 2012
I'm confused about why you'd want to nest a login view within itself... There's a "yo dawg I heard" joke in here somewhere.
If you don't have all your controllers available, you will indeed need to add it yourself there. We could wrap that up in a a
router.addControllermethod to have a standard way to add them later.Onkelborg commentedon Jul 3, 2012
I don't want a login view inside itself, it was just a test. A more practical example would have been a project manager, for example, where a Task could have other Tasks. In that case you would end up with a task inside a task inside a task.. :)
(But then I suspect the router has to be rewritten a bit more to allow "on-the-fly" routes as the length of the chain isn't known until runtime)
edit:
My point is that I think it's a bad idea to store the instances in the router, I think they are more related to the route. And I don't think they should be store with the same, but intial lower case, name as their constructor - consider a diff-tool with two windows for comparing two files side-by-side. I'm thinking somewhere along the path of storing the controller attached, somehow, to the outlet it's rendered in?
I do think this is necessary to address, it's a problem, and it's a lot easier to fix now without having to care about backwards compatibility
wagenet commentedon Jul 4, 2012
@wycats, @tomdale You made a lot of the decisions here. It would be great if you could chime in.
stas commentedon Oct 15, 2012
@Onkelborg you should use
connectOutletand set thecontextto what view and controller you want to use.It has nothing to do with singleton or not.
Also take a look at source code of the
connectOutlet:https://github.com/emberjs/ember.js/blob/master/packages/ember-views/lib/system/controller.js#L133
wagenet commentedon Oct 19, 2012
I don't think we're going to change anything here. @Onkelborg hopefully @stas's suggestion was useful.
stas commentedon Oct 19, 2012
Oh, one important thing, in order to leverage from existing routes, don't forget to initialize the
targetattribute with current router instance.[BREAKING] Remove AMD bundles for Ember 7.0
[BREAKING] Remove AMD bundles for Ember 7.0