Results 1 to 2 of 2

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

  1. #1
    Sencha User
    Join Date
    Mar 2014
    Posts
    2
    Answers
    1
    Vote Rating
    1
      0  

    Default Using pre-defined constant string as the key in firing and handling application event

    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':

    Code:
    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:
    Code:
    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:
    Code:
    this.application.on({
                mailclient.config.Runtime.APPEVT_FOLDER_FOLDERSELECTED: this.onMailFolderChanged,
                scope: this
            });
    Any advises please? (sorry for my English)

  2. #2
    Sencha User
    Join Date
    Mar 2012
    Location
    Lawrence, KS
    Posts
    462
    Answers
    65
    Vote Rating
    91
      0  

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •