PDA

View Full Version : [CLOSED] [4.0.2a] Ext.app.Application autoCreateViewport issue



AndreaCammarata
30 Sep 2011, 6:53 AM
Hi guys,
I notice that if I set the config param



autoCreateViewport: true


in an Ext.app.Application configuration, this block the application controller to auto call it's "init" function.
The viewport is created without any problem, but the controller "init" function is never called.

EDIT: Please mark this Thread as fixed! I simply had a cache problem. Sorry!

mitchellsimoens
30 Sep 2011, 9:52 AM
There are ways to disable cache in Chrome and Firefox... in the Chrome Dev tools, at the bottom-right of the console tab there is a gears icon... in there you can disable cache.

For Firefox, I'm not sure if there is something built-in or in Firebug but there are extensions to do this.

LesJ
30 Sep 2011, 12:14 PM
In Firefox, click the small triangle by the Net tab and then check Disable Browser Cache.

rubyrain
14 Nov 2011, 9:50 AM
init is still not called if autoCreateViewport: true in ext 4.0.7

To reproduce it, download Pandora app from guide, http://cdn.sencha.io/img/architecting-your-app-in-ext-js-code.zip, set extjs path correctly, then change app.js with the following:


Ext.Loader.setConfig({
enabled: true
});

Ext.application({
name: 'Pandora',

autoCreateViewport: true,

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

// Doesn't get called
init: function(app) {
console.log(app);
},

// onLanuch: doesn't work. use launch:
launch: function() {
console.log('launch');
}
});

mitchellsimoens
14 Nov 2011, 10:49 AM
autoCreateViewport has nothing to do with the init not being called. Ext.app.Application is responsible for executing all the Ext.app.Controller's init method so what is going to fire Ext.app.Application's init method?

rubyrain
14 Nov 2011, 11:02 AM
This is what doc says. http://docs.sencha.com/ext-js/4-0/#!/api/Ext.app.Application-method-init

init (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext.app.Controller-method-init)( Ext.app.Application (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext.app.Application) application )templateA template method that is called when your application boots. It is called before the Application (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext.app.Application)'s launch function is executed so gives a hook point to run any code before your Viewport is created.

I thought by setting init method, I could have a hook before viewport is created. Can you tell me how to get the hook before viewport is created then?

mitchellsimoens
14 Nov 2011, 11:20 AM
I see the docs don't match the source code. This is due to Ext.app.Application extending Ext.app.Controller.

So to do this, you can do one of two things as I see it:


All your controller's init methods are called before the viewport class is created so that may be where you should put things
If you still want it to be in Ext.app.Application then you can do some magic


Magic:

Ext.define('Test.view.Viewport', {
extend : 'Ext.container.Viewport',
alias : 'widget.test-viewport',

layout : 'fit',

initComponent: function() {
this.items = [
{
xtype : 'panel',
frame : true,
html : 'Hi',
title : 'Hello'
}
];

this.callParent(arguments);
}
});


Ext.application({
name : 'Test',

autoCreateViewport : true,

onBeforeLaunch: Ext.Function.createInterceptor(Ext.app.Application.prototype.onBeforeLaunch, function() {
console.log(Ext.ComponentQuery.query('test-viewport')); // return empty Array because Viewport hasn't been created
}),

launch: function() {
console.log(Ext.ComponentQuery.query('test-viewport')); // return Viewport in an Array
}
});

So Ext.Function.createInterceptor takes one function and executes it before another. The second argument where we do a console.log will execute before the first argument.

rubyrain
14 Nov 2011, 11:49 AM
Magic doesn't work. I tried intercepting onBeforeLaunch in Ext.application, but I get Ext.app is undefined error. However, option #1 makes sense and I'm gonna go with it.

Thank you very much mitchellsimoens. :)

mitchellsimoens
14 Nov 2011, 12:53 PM
Magic doesn't work. I tried intercepting onBeforeLaunch in Ext.application, but I get Ext.app is undefined error. However, option #1 makes sense and I'm gonna go with it.

Thank you very much mitchellsimoens. :)

Option 1 is what I would prefer. The "magic" way was tested on 4.1-PR1 as fully working.