-
Notifications
You must be signed in to change notification settings - Fork 10
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
Question about namespaces #1
Comments
I put // assumes you've already defined an AppController somewhere else.
/*****************************************************************************/
/* Routes */
/*****************************************************************************/
var AppController = App.controllers.AppController;
/**
* All products
*/
App.controllers.products_index = AppController.extend({
pageTitle: 'All products',
name: "products.index",
template:"items_grid",
waitOn:function(){
return Meteor.subscribe('allProducts');
},
data:function(){
return {
items: Products.find({}, {sort: {model: 1} }),
filters: []
}
}
});
/**
* View product.
*/
App.controllers.show_product = AppController.extend({
name: 'products.show',
template: 'item_show_details',
pageTitle: 'Product Details',
disableMeta: true,
collection: 'products',
fastRender: true
});
Router.route("/products", {controller: Products.controllers.index});
Router.route("/products/new", {controller: Products.controllers.index, filter: [{new: true}]});
Router.route('/products/:slug', {controller: Products.controllers.show}); As you can see, controllers are used just like routes except you can have multiple routes share the same controller, so it allows you to create 'groups'; Controllers can inherit other controllers, so if you defined an Oh, and in case you didn't notice from that last sentence: when you extend a controller and define a callback that was already defined by the controller you extend, you don't overwrite it - you append to it. I believe routers don't have this behavior, so in certain situations controllers are handy. Last, notice how I defined some arbitrary keys on the controllers (e.g. var ctor = Iron.controller();
var pageTitle = ctor.pageTitle;
Session.set('pageTitle', pageTitle); Hopefully that illustrates when they could be useful. As for the secondary namespace - it's just showing that if you want, you can define more namespaces; It's totally up to you. Let me know if that clears things up. I'm going to keep this open as a reminder to clarify a few things in the repo. |
Thanks for the explanation. I had a suspicion it was for route controllers. I actually use a similar pattern, but with Flow Router (using route groups). |
Thanks a lot for the package, I just have a couple of questions about the namespaces defined in app:lib's core.js:
What do you use App.controllers for?
What is the Secondary namespace for?
The text was updated successfully, but these errors were encountered: