View Full Version : Sencha MVC components: Registering vs. Namespaces

24 Feb 2011, 12:26 PM
Hi all, I'm new to Sencha Touch, and am trying to understand Sencha MVC. I've looked at the Kiva Mobile example, as well as the Contacts (http://www.sencha.com/learn/Tutorial:A_Sencha_Touch_MVC_application_with_PhoneGap) sample app. Each has a different way of instantiating and referring to its models and views. Why are there two different ways? Is there a best practice for instantiating components within an MVC structure?

Kiva registers models, controllers and views

Ext.reg('kivaMain', kiva.views.Main);
Ext.reg('loansList', kiva.views.List);
Ext.regModel("Loan", {..});
Ext.regController("loans", {..});

So they can be referred by xtype, eg. in /controllers/loans.js

list: function() {
this.listView = this.render({
xtype: 'kivaMain',
listeners: {
scope : this,
filter: this.onFilter,
selectionchange: this.onSelected
}, Ext.getBody()).down('.loansList');

Contacts sample app does not register it's controllers or views after instantiating them:

app.controllers.contacts = new Ext.Controller({..});
app.views.ContactDetail = Ext.extend(Ext.Panel, {..});

And are referred simply using Ext.apply:

initComponent: function() {
//put instances of cards into app.views namespace
Ext.apply(app.views, {
contactsList: new app.views.ContactsList(),
contactDetail: new app.views.ContactDetail(),
contactForm: new app.views.ContactForm()
//put instances of cards into viewport
Ext.apply(this, {
items: [
app.views.Viewport.superclass.initComponent.apply(this, arguments);

Any help would be appreciated on the best practice to build MVC components, thank you.

24 Feb 2011, 12:49 PM
Could have something to do with registering xtypes: http://www.sencha.com/forum/showthread.php?116695-Why-register-xtypes/page3&highlight=componentmgr

22 Apr 2011, 5:50 AM
I'm curious about the same thing! Whats the best practice? I'm also too new to Sencha Touch to fully understand potential advantages and drawbacks of the different approaches.

9 Aug 2011, 7:50 PM
Did anyone come up with any answers about this elsewhere? There are so many different ways of doing these things, it's quite hard to learn the 'right' way early on...