Results 1 to 4 of 4

Thread: Controller map is always empty

    You found a bug! We've classified it as EXTJS-19273 . We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.
  1. #1
    Sencha Premium User alexander.urban's Avatar
    Join Date
    Nov 2013
    Posts
    320

    Default Controller map is always empty

    Hello Sencha team,

    I have a bug to report in the getController function that makes conversion of MVC model apps from 4.2.2 to 6.0.1 hard and introduces nasty bugs in my application.

    Please browse to

    http://examples.sencha.com/extjs/6.0...app/index.html

    and open browser console. Type:

    Ticket.app.controllers.map

    Return is {}

    But the code comment says

    controller = controllers.get(name);
    // In a majority of cases, the controller id will be the same as the name.
    // However, when a controller is manually given an id, it will be keyed
    // in the collection that way. So if we don't find it, we attempt to loop
    // over the existing controllers and find it by classname

    where get() is defined as

    get: function(key) {
    var me = this,
    mk = me.map[key],
    item = mk !== undefined ? mk : (typeof key == 'number') ? me.items[key] : undefined;
    return typeof item != 'function' || me.allowFunctions ? item : null;
    },

    so in none of cases, controllers.get(name) will return anything but "undefined", except when you provide the name as an integer index, like Ticket.app.getController(0). Since you wouldn't locate a controller by index, you could say that it will always run into the loop.

    As a side effect, the short form getController("Root") does not work correctly; it should either return the existing Root controller or undefined; but it should not create a second instance of the controller.

    I guess

    controllers.add(controller);

    should be sth. like

    controllers.add(name,controller);

    although I am not sure about the details.

    This happens in ExtJS 6.0.1 commercial.

    Kind regards,

    Alexander

  2. #2
    Sencha User tobiu's Avatar
    Join Date
    May 2007
    Location
    Munich (Germany)
    Posts
    2,751

    Default

    related to: https://www.sencha.com/forum/showthread.php?301510

    as a quick workaround-fix to fetch controllers defined inside the controllers array of the app and to ensure they are not instanciated multiple times (true flag):

    Code:
        /**
         * https://www.sencha.com/forum/showthread.php?301510
         * @param name
         * @returns {*}
         */
        getMainController : function(name) {
            if (name.indexOf('MyApp.controller.') < 0) {
                name = 'MyApp.controller.' + name;
            }
    
            return this.getController(name, true);
        }
    Best regards
    Tobias Uhlig

  3. #3
    Sencha - Support Team bjdurham85's Avatar
    Join Date
    Mar 2014
    Posts
    962

    Default

    Thanks for the information and report, I've linked to the open thread in our bug tracking system.


    Regards,
    Bryan

  4. #4
    Ext JS Premium Member
    Join Date
    Aug 2011
    Location
    Greenville, SC
    Posts
    181

    Default

    Basically, it looks like there is an issue with the removal of id from the getController function. This could also possibly be an issue in Ext 5. Here is the code I added to my Application.js to resolve the issue.


    Code:
    initControllers: function() {
        var me = this,
            controllers = Ext.Array.from(me.controllers);
    
    
        me.controllers = new Ext.util.MixedCollection();
        // ADDED - This allows a key to be set for controllers
        // in a mixed collection without an id property specified.
        // The older controller mechanism use to always set up an
        // id.  Now if you do not manually specify one, then
        // the framework creates an _id.
        Ext.override(me.controllers, {
            getKey : function(o) {
                return o.id || o._id;
            }
        });
    
    
        for (var i = 0, ln = controllers.length; i < ln; i++) {
            me.getController(controllers[i]);
        }
    },
    getController: function(name, /* private */ preventCreate) {
        var me          = this,
            controllers = me.controllers,
            className, controller, len, i, c, all, moduleClassName;
    
    
        controller = controllers.get(name);
    
    
        // In a majority of cases, the controller id will be the same as the name.
        // However, when a controller is manually given an id, it will be keyed
        // in the collection that way. So if we don't find it, we attempt to loop
        // over the existing controllers and find it by classname
        if (!controller) {
            moduleClassName = me.getModuleClassName(name, 'controller');
    
    
            all = controllers.items;
            for (i = 0, len = all.length; i < len; ++i) {
                c = all[i];
                className = c.getModuleClassName();
                // ADDED - check the moduleClassName as well
                // This will allow usage of get in two ways:
                // 1.) MyApp.getApplication().getController('MyApp.controller.base.Foo');
                // 2.) MyApp.getApplication().getController('base.Foo');
                                 if (className && (className === name || className === moduleClassName)) {                    controller = c;
                        break;
                    }
                    controller = c;
                    break;
                }
            }
        }
    
    
        if (!controller && !preventCreate) {
            controller = Ext.create(moduleClassName, {
                application: me,
                moduleClassName: moduleClassName
            });
    
    
            controllers.add(controller);
    
    
            if (me._initialized) {
                controller.doInit(me);
            }
        }
    
    
        return controller;
    }
    Bryan

Similar Threads

  1. Replies: 2
    Last Post: 19 Nov 2014, 1:13 AM
  2. Replies: 2
    Last Post: 31 Jan 2012, 12:51 PM
  3. Replies: 3
    Last Post: 13 Jan 2012, 12:16 AM
  4. Disable set active item in a controller when data returned is empty
    By pkvenu in forum Sencha Touch 1.x: Discussion
    Replies: 2
    Last Post: 28 Dec 2011, 9:24 AM

Posting Permissions

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