0

I'm noticing that uses and requires from the Ext.class aren't working using minified js generated by Sencha cmd tool. I'm defining two classes,suppose class A and B, B class requires that Instace of A should be created which has an ajax call in it's contructore to pull some values from the server side code, this works perfectly when I'm using regular js structure having classes, store, models,etc..but that is not the case after building minified js using Secha cmd, Is it possible to instatiate these singletone synchronously before application starts loading views or anyother suggestion you would like to suggest to solve this issue? Please note I'm using ExtJs 4.2

Ext.define('A', {
    alternateClassName:'AClass',
    singleton:true,
    constructor: function(config) {
        this.initConfig(config);
        Ext.Ajax.request({
            url : 'XXX.html',
            method : 'POST',
            headers: { 'Content-Type' : 'application/json',

                    },
            success : function(response, opts) {
                appProps = JSON.parse(response.responseText).items;
            },
            failure : function(response, opts) {
            }
        });
        return this;
    },

    config: {
        appProperties: '%XXX_PROPPERTIES%',
        accSysMnemonic:'',
        assetTypeForExAccCat:'',
        appProps : ''
    },

    getValue : function(key){
        props = appProps;
        var value = props[key];
        return value;
    }});


Ext.define('B', {
            requires:['A'],
            alternateClassName : 'BClass',
            singleton : true,
            config : {

            },
            constructor : function(config) {
                this.initConfig(config);

                return this;
            },
            hasvalue : function(val) {

                if(A.getValue('XXX') === 'false' || A.getValue('XXX') === undefined){
                    console.log('XXX is false');
                    return true;
                }else{
                return false;
            }
}});
user3247727
  • 174
  • 1
  • 7
  • Can you add some code so we know how you're doing this? – arthurakay Mar 23 '15 at 12:47
  • @arthurakay, added required code, this works fine when I have separate js files but doesn't works after using minified js generated using Sencha cmd while application is loading. – user3247727 Mar 23 '15 at 14:19

1 Answers1

0

If I understand you correctly, you don't want "B" to initialize itself until after "A" has completed it's Ext.Ajax.request. That correct?

You could do that in a number of ways, but the simplest might be to force the Ajax request to be synchronous (blocking the script execution until it completes).

Per the Ext JS docs you can just set async : false on the request options to force it in this case.

Alternatively you could setup some event/state logic to avoid the script execution block.

arthurakay
  • 5,631
  • 8
  • 37
  • 62
  • Thaks for your answer, my concern is why requires attribute on class doesnt work as excpected after generating minified JS using Sencha cmd? – user3247727 Mar 24 '15 at 08:26
  • API you are refering to is of Ext JS 5.1, I looking for some solution in Extjs 4.2 – user3247727 Mar 24 '15 at 08:30
  • In Ext JS 4.2.x, the `async` option still exists, it just isn't documented. Take a look at the code inside `Ext.data.Connection` and you'll see :-) – arthurakay Mar 25 '15 at 11:21
  • It doesn't works in my case. I have resolved it by implementing workaround which replace value for appProps using server side response wrapper. – user3247727 Mar 25 '15 at 11:43