PDA

View Full Version : Modularizing code - running into problems



kkleinwi
30 Jan 2012, 12:16 PM
So I have my prototype app working, and now I'd like to refactor it to make it more modular. I'd like to split the classes into three "packages": general utilities, framework classes, and application-specific classes.

I'm trying to do this by using Ext.Loader.setPath(). However as soon as I do this, the application breaks in a very odd way.

My app.js has this:


Ext.Loader.setPath("MyUtils", "forms/utils"); // this is my new utility package

Ext.application({
name: 'Nwform',

appFolder: 'forms/app',

controllers: [ 'Wizard' ],

launch: function() {
this.getController('Wizard').launch();
}
});


Then one of my view classes has:



Ext.require("MyUtils.ui.TextSsn"); // used to be Nwform.utils.TextSsn

Ext.define("Nwform.view.cards.Card1", {
// usual stuff here
});


However as soon as I move the TextSsn class from Nwform.utils to MyUtils.ui, I get the following exception during the application initialization.

Uncaught TypeError: Cannot read property 'Container' of undefined

This is thrown in Table.js line 217. Inspecting this code shows that Ext.grid.header.Container is undefined.

What gives?

mitchellsimoens
30 Jan 2012, 12:33 PM
Does Nwform.view.cards.Card1 require MyUtils.ui.TextSsn?

kkleinwi
30 Jan 2012, 12:36 PM
Yes it does, although it is referenced by an xtype alias "widget.cel_textssn" and not instantiated directly.

mitchellsimoens
30 Jan 2012, 12:38 PM
Ok, so this is not the correct way to say one class requires another:


Ext.require("MyUtils.ui.TextSsn"); // used to be Nwform.utils.TextSsn

Ext.define("Nwform.view.cards.Card1", {
// usual stuff here
});

Not sure if this will fix your issue, just the first thing that I saw. This is how to tell one class to require another class:


Ext.define("Nwform.view.cards.Card1", {
....
requires : [
'MyUtils.ui.TextSsn'
],
....
});

kkleinwi
30 Jan 2012, 1:09 PM
Fixed that n00b error, didn't help.

Turns out that I'm an i-d-i-o-t. I moved the class, but forgot to change the class name in Ext.define(). Doh!

börn
30 Jan 2012, 11:20 PM
that's really a doh! but never mind - that's a classic one! ;) and happens to me all the time. This is the time i hate dynamic languages ;) .. but it didn't take very long...