1. #1
    Sencha User
    Join Date
    Apr 2008
    Posts
    80
    Vote Rating
    0
    g13013 is on a distinguished road

      0  

    Default [SOLVED] Require and CallBack

    [SOLVED] Require and CallBack


    Hi everyone,

    I am trying to load somme files before calling a function, but it seems that that callBack function is not called, any idea ?

    Code:
    Ext.require(['interface.common.Functions',
                     'interface.common.Msg',
                     'interface.common.Config'],MainApp.Start,MainApp);
    
    MainApp.Start = function () {
        var o = Ext.create('MainApp.view.MainContainer');
        Ext.create('Ext.container.Viewport',{
            layout:'fit',
            items : [o]
        });
    };

  2. #2
    Sencha User
    Join Date
    Jun 2011
    Posts
    55
    Vote Rating
    1
    Gabanjo is on a distinguished road

      0  

    Default


    I think it's because you seem to define MainApp.Start after you invoke the Ext.require.

    The following works for me:

    Code:
    var app = {};
    app.start = function() {
        Ext.create('Ext.app.Application',{
            name: 'hermes',
            appFolder : 'app',
            controllers: [
        ],
            launch : function() {
                Ext.create('Ext.container.Viewport',{
                    layout : 'border',
                    items : [
                        {   region: 'center', html: 'hello world' }
                    ]
                });
            },
        });
      }
    Ext.require('Ext.state.*',app.start,app);

  3. #3
    Sencha User
    Join Date
    Apr 2008
    Posts
    80
    Vote Rating
    0
    g13013 is on a distinguished road

      0  

    Default


    Thank you for the reply, you were right. I thought that the fonction has to be defined before the load of all files, as the loading off all files takes more time , But I see that the callBack function is chacked before starting loading files as shown in the definition of require function :

    Code:
            /**
             * Loads all classes by the given names and all their direct dependencies;
             * optionally executes the given callback function when finishes, within the optional scope.
             *
             * {@link Ext#require Ext.require} is alias for {@link Ext.Loader#require Ext.Loader.require} for convenience.
             *
             * @param {String/String[]} expressions Can either be a string or an array of string
             * @param {Function} fn (Optional) The callback function
             * @param {Object} scope (Optional) The execution scope (`this`) of the callback function
             * @param {String/String[]} excludes (Optional) Classes to be excluded, useful when being used with expressions
             */
            require: function(expressions, fn, scope, excludes) {
                var filePath, expression, exclude, className, excluded = {},
                    excludedClassNames = [],
                    possibleClassNames = [],
                    possibleClassName, classNames = [],
                    i, j, ln, subLn;
    
                expressions = Ext.Array.from(expressions);
                excludes = Ext.Array.from(excludes);
    
                fn = fn || Ext.emptyFn;
    
                scope = scope || Ext.global;

Thread Participants: 1