PDA

View Full Version : Listen to application events from non-controllers?



karpatyx@ya.ru
5 Dec 2011, 9:34 AM
Hello guys,

Sorry for kind of a stupid question, but I believe that anybody of you can answer in 10 seconds while I haven't figured answer yet in 25 minutes :).

I have singleton class and I want it listening to application-level events:


Ext.define('ikhtml.utils.windowManager.windowManager', {
singleton: true,


constructor: function ()
{
this.application.on({
loggedOut: this.onLoggedOut,
scope: this
});
}
...

But "application" property is valid only for controllers. How to access application instance from other classes?

Sure, I can pass it as parameter or set as property, but there should be much better solution.

Thanks for YOUR time.

ldonofrio
5 Dec 2011, 10:07 AM
If your windowManager class have not widgets in it i'll simply rewrite it as controller

karpatyx@ya.ru
6 Dec 2011, 2:38 AM
If your windowManager class have not widgets in it i'll simply rewrite it as controller

Sorry, but I'll disagree.

Controllers have clearly defined role in MVC. My window manager is not a controller, it's class. I wouldn't like adding mess to application just to get single reference.

tobiu
6 Dec 2011, 3:40 AM
since you probably have set a namespace for your app, i would try to directly address it.

karpatyx@ya.ru
6 Dec 2011, 9:12 AM
I tried using namespace but without success:

ikhtml.on({
...
});

How I decided to move on:


App.js:

launch: function()
{
windowManager.init(this);
...
},

windowManager.js:

init: function(application)
{
this.application = application; // got reference here
this._subscribeToEvents();
},



If anybody knows more elegant decision, I would be much grateful for.