Philipp
Philipp

Reputation: 13

Where do I put my global helper functions if they are needed before Ext.application() is being executed?

Let's say we have

Ext.application({
    name: 'APP',

    //this is my global helper method.
    determineSomething: function() {
        return true;
    }
});

and a view that should access the method determineSomething():

Ext.define('APP.view.Main', {
extend: 'Ext.Panel',

config: {
    myConfigValue : APP.app.determineSomething()
}});

This will work fine as long as you use the Sencha class loading system (because the js-file with this Main-View is loaded by Sencha after APP is available.).

But now let's say we want to minify our script. This means that the browser parses the Main.js file before the Sencha application is loaded. But at this time APP is not yet ready and we can not access it.

One solution would be to simply make a non ext config class / array / whatever with the method but is this a nice solution? What would be a clean solution for this problem?

Upvotes: 0

Views: 928

Answers (1)

ThinkFloyd
ThinkFloyd

Reputation: 5021

I would keep my helper functions into a singleton Helper class which gets instantiated whenever app is loaded. For example this is how my helper class look like:

Ext.define('MyntraTabApp.util.Helper', {
    singleton : true,
    alternateClassName : 'Helper',
    determineSomething : function(){
        // do something
    }
});

I can use it like this wherever I want

Helper.determineSomething();

Upvotes: 1

Related Questions