1. #1
    Sencha User castitas's Avatar
    Join Date
    Sep 2011
    Location
    US
    Posts
    116
    Answers
    3
    Vote Rating
    2
    castitas is on a distinguished road

      0  

    Default Answered: How can I tell if a grid has plugins?

    Answered: How can I tell if a grid has plugins?


    I have button that serves two grids. In the handler, it has this:

    Code:
            if(button.up('grid').getPlugin('roweditor').editing) {
                ...
    One grid has plugins, and it works fine. The other throws "plugins is undefined". I could use
    Code:
            var grid = button.up('grid');
            if(grid.plugins && grid.getPlugin('roweditor').editing) {
                ...
    but that depends on the plugins attribute. Can anyone think of a better way?
    word

  2. If calling getPlugin causes an error to be thrown I'd say it's a bug. Your workaround looks sensible but it'd probably be worth filing it in the bugs forum to get it fixed properly.

  3. #2
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,592
    Answers
    541
    Vote Rating
    323
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      0  

    Default


    If calling getPlugin causes an error to be thrown I'd say it's a bug. Your workaround looks sensible but it'd probably be worth filing it in the bugs forum to get it fixed properly.

  4. #3
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,982
    Answers
    662
    Vote Rating
    453
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    You should be able to call without error. Is this present in a older/newer release?

    Code:
    pluginId: 'myPluginId',
    grid.getPlugin('myPluginId');
    Scott.

  5. #4
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,592
    Answers
    541
    Vote Rating
    323
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      0  

    Default


    @scottmartin. I believe the problem being observed is that an error is thrown if the component doesn't have any plugins. For consistency (and common sense) it should just return undefined if the plugin id isn't found.

  6. #5
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,982
    Answers
    662
    Vote Rating
    453
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    Understood... this seems to work:

    Code:
    var myPlugin = grid.getPlugin('IdoNoExist');
    if (myPlugin === undefined) { console.log('undefined'); }
    Scott.

  7. #6
    Sencha Premium Member
    Join Date
    Mar 2007
    Posts
    64
    Vote Rating
    2
    ojintoad is on a distinguished road

      1  

    Default


    A developer on my team thinks this is a bug and I agree with him. I'll make his case below: I just created this JSFiddle http://jsfiddle.net/LMaaM/.

    This is based on 4.1.1 (not 4.1.3) which is latest. The test is obviously pretty contrived. However, I think it still illustrates the bug since in one case it works fine and in the other case it fails. This has to do with the fact that the code for the getPlugins code in Ext.AbstractComponent is:

    Code:
        /**
         * Retrieves a plugin by its `pluginId` which has been bound to this component.
         * @param {String} pluginId
         * @return {Ext.AbstractPlugin} plugin instance.
         */
        getPlugin: function(pluginId) {
            var i = 0,
                plugins = this.plugins,
                ln = plugins.length; //problematic
            for (; i < ln; i++) {
                if (plugins[i].pluginId === pluginId) {
                    return plugins[i];
                }
            }
        },
    My developer's thought is that the plugins.length check fails since plugins doesn't exist. Plugins isn't obligated to be defined.

    The AbstractComponent.constructPlugins method isn't obligated to assign an array to plugins or return an array that would be assign to plugins from any calls while initializing the component. The configuration option isn't defined as an array by default (wisely) either.

    I'd say there's two options to repair:
    1. getPlugins (and any other methods utilizing the plugins member variable) could guard against the case that the plugins array is undefined.
    2. plugins could be initialized as an empty array by default, reducing the need to check

    I'd guess the latter would be the better choice from a future proofing standpoint.

  8. #7
    Sencha Premium Member
    Join Date
    Mar 2007
    Posts
    64
    Vote Rating
    2
    ojintoad is on a distinguished road

      0  

    Default


    Bug was eventually recognized as EXTJSIV-8568: http://www.sencha.com/forum/showthre...ed-as-an-array