Reputation: 11
I get the conceptual aspects of MVC and how they are generally implemented. In emberjs the conventions approach makes sense and is seemingly straightforward. But, how do you decide when to use an objectcontroller vs. an indexedcontroller and such, and how is one to learn or retain the conventions so you can make quick logical programmatic design decisions as to which direction or approach you take?
I mean how do you commit such minute conventions like these into logical thinking?
If you don't specify a route handler for the post route (App.PostRoute), Ember.js will still render the post template with the app's instance of App.PostController.
If you don't specify the controller (App.PostController), Ember will automatically make one for you based on the return value of the route's model hook. If the model is an Array, you get an ArrayController. Otherwise, you get an ObjectController.
If you don't specify a post template, Ember.js won't render anything!
http://emberjs.com/guides/concepts/naming-conventions/#toc_route-controller-and-template-defaults
Also, correspondingly are there conventions around views vs. a component vs. a property and how those all funnel out from the conventions around routing, routers, controllers?
thanks -
David
Upvotes: 1
Views: 111
Reputation: 47367
Controller's are really decorators. They proxy properties from the controller to the model beneath it. As such there are three different types of controllers. ArrayController
, ObjectController
, and Controller
.
ArrayController
is backed by a collection
ObjectController
is backed by a single object
Controller
doesn't have any object backing it
Really the trick is to start small. Do a single template, single route, single controller. Don't attempt to add anything else until you run into a problem you don't know how to solve.
Example: http://emberjs.jsbin.com/sohijunu/1/edit
Once you get the gist of a single route, single controller, single template, you can start experimenting with multiple routes etc. It's a lot like college, a time of experimentation, but you start small.
Example: http://emberjs.jsbin.com/OxIDiVU/726/edit
Upvotes: 1