I've been trying to wrap my head around using CanJS for building a complex, "real" app/product at my company. I have a few basic "best practices" questions. Hopefully these aren't out of place.
Assuming I have this code:
So my questions are:
Assuming I have this code:
- Contact = can.Model({
findAll: "GET /contacts"
},{}); - Contacts = can.Control({}, {
init: function() {
var self = this;
Contact.findAll({}, function(contacts) {
self.options.contacts = contacts;
self.element.html(can.view("contactsList.ejs", contacts));
});
}
}); - $(document).ready(function() {
app = {};
app.contacts = new Contacts("#contacts");
});
So my questions are:
- Is wiring everything up via the "app" global good or bad? If it's bad, does CanJS offer some other way of accessing the controller instances that are created (i.e. can.controls.Contacts[0] or some such)?
- Is there a standard/better way to access a controller's model list/instances than what I've done there (i.e. the "self.options.contacts = contacts;" line from above)? So that later if I need to get that list again, I can just access app.contacts.options.contacts (or write a getter to make that less typing)?
- Or perhaps the code above is completely off base...?
Thanks in advance!