PDA

View Full Version : Extend Ext.Application



schmidt@archomedia.com
8 Nov 2012, 5:02 AM
Hi,

based on the pandora example I tried to extend Ext.app.Application like shown in the section "Deriving from Ext.app.Application" here (http://docs.sencha.com/ext-js/4-1/#%21/api/Ext.app.Application). I get something like this:



Ext.define('AbstractApplication', {
extend: 'Ext.app.Application',

constructor: function (config) {
config = config || {};
Ext.apply(this, config);

var me = this;
me.callParent(config);
},

launch: function () {
var me = this;
me.initBar();
},

bar: function () {
console.log('bar called');
}
});


Ext.application({
extend: 'AbstractApplication',
name: 'Pandora',

autoCreateViewport: true,

models: ['Station', 'Song'],
stores: ['Stations', 'RecentSongs', 'SearchResults'],
controllers: ['Station', 'Song'],

launch: function () {
var me = this;
me.callParent();
}
});


But I get an error saying 'Error: this.callParent() was called but there's no such method (onBeforeLaunch) found in the parent class (Ext.app.Controller)' on line 'Ext.application > launch > me.callParent'

If I do it the way described here (http://www.sencha.com/forum/showthread.php?238496) with
Ext. onReady it works faultless. May somebody please tell me why the example from the docs is not working or what I'm doing wrong?

vietits
8 Nov 2012, 5:40 AM
Ext.application() is in fact will:
1. Load Ext.app.Application class.
2. On Ext.ready, it will create an instance of Ext.app.Application.


Ext.application = function(config) {
Ext.require('Ext.app.Application');


Ext.onReady(function() {
new Ext.app.Application(config);
});
};

So with your code:


Ext.application({
extend: 'AbstractApplication', // (1)
name: 'Pandora',


autoCreateViewport: true,


models: ['Station', 'Song'],
stores: ['Stations', 'RecentSongs', 'SearchResults'],
controllers: ['Station', 'Song'],


launch: function () {
var me = this;
me.callParent(); // (2)
}
});

(1): This line has no effect because Ext.app.Application has no config named 'extend'.
(2): This line cause the error you mentioned in your post. Because Ext.app.Application is extended from Ext.app.Controller so this line will call Ext.app.Controller.launch(). However, because Ext.app.Controller does not define launch() method so it will cause error.

schmidt@archomedia.com
8 Nov 2012, 5:57 AM
hm ok, thank you vietits

Though why does the docs (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.app.Application) give this



Ext.define (http://docs.sencha.com/ext-js/4-1/#!/api/Ext-method-define)('MyApp.app.Application', {
extend: 'Ext.app.Application (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.app.Application)',
...
});
Ext.application (http://docs.sencha.com/ext-js/4-1/#!/api/Ext-method-application)({
extend: 'MyApp.app.Application',

name: 'Blog',
models: ['Post', 'Comment'],
controllers: ['Posts', 'Comments'],

launch: function() {
...
}
});

as an example for extending Ext.app.Application? Most of the times I look at the docs, the given examples don't work. This is not a quality mark.

vietits
8 Nov 2012, 3:42 PM
What Ext version do you use? The document on the web is for 4.1.3. Maybe this is applied for Ext 4.1.2 or Ext 4.1.3 but this is not applied for Ext 4.1.1a or earlier.

schmidt@archomedia.com
8 Nov 2012, 11:15 PM
this could be the reason, I'm using 4.1.1. Is there a doc especially for 4.1.1?

vietits
9 Nov 2012, 12:06 AM
If you downloaded and unziped Ext 4.1.1, then the documents is under "docs" folder.