PDA

View Full Version : Using pre-defined constant string as the key in firing and handling application event



nguyenkimkong
31 Mar 2014, 11:39 AM
Hello,

My issue is: using pre-defined constant string as the key in controller classes in "firing and handling application event"

Controller A fire application event with key 'appevent_folder_folderselected':


Ext.define('mailclient.controller.A', {
extend: 'Ext.app.Controller',
init: function() {
this.control({
'treepanel': {
itemclick: this.mailFolderChanged
}
});
},
mailFolderChanged: function(view, record)
{
this.application.fireEvent('appevent_folder_folderselected', view, record);
}
});

On the Controller B handle application event:

Ext.define('mailclient.controller.B', {
extend: 'Ext.app.Controller',
init: function() {
this.application.on({
'appevent_folder_folderselected': this.onMailFolderChanged,
scope: this
});


},
onMailFolderChanged: function(view, record)
{
//dosomething
}
}
);


The coding convention suggests the string 'appevent_folder_folderselected' should be a global constants.

I did apply all possible ways. There have a global js file define singleton class that contain the string. Then do the register that class with application requires[]

Now if replace the real string in both Controller A and B with the global constant string, it works at Controller A, but doesn't work at Controller B:


this.application.on({
mailclient.config.Runtime.APPEVT_FOLDER_FOLDERSELECTED: this.onMailFolderChanged,
scope: this
});

Any advises please? (sorry for my English)

greg.barry
3 Apr 2014, 8:31 AM
We wrote a newsletter article regarding global constants, variables, and functions a little while ago. Perhaps this will steer you in the right direction:

http://www.sencha.com/blog/top-support-tips-july-2013

Thanks!
Greg