Greg Lafrance
Greg Lafrance

Reputation: 809

How can I override Ext.Loader?

I put a copy of the Ext.Loader file in my myApp\overrides folder.

I also edited sencha.cfg so it is like this:

app.classpath=${app.dir}/app,${app.dir}/app.js,${app.dir}/overrides

I also put this in my app.js requires:

requires: [
    'AMC.overrides.Loader'
]

Tried this too:

requires: [
    'overrides.Loader'
]

But when I build I still get this error:

com.sencha.exceptions.ExBuild: Failed to find any files for C:\myworkspace\myApp\app.js::ClassRequire::overrides.Loader

Upvotes: 1

Views: 741

Answers (2)

Nux
Nux

Reputation: 10032

Ext.Loader has a paths configuration that allows you to specify custom paths for each namespace.

For example if your AMC.overrides.whatever.ClassName paths is /overrides/whatever/ClassName.js, then you would need configuration like this:

Ext.Loader.setConfig({
    paths: {
        'AMC.overrides': scriptsRoot + '/overrides',
    }
});

I don't use the Sencha Builder (sench-cmd), but above works fine in the browser and it should work for the builder too.

Obviously scriptsRoot would have to be defined as a global in your HTML, JSP or whatever you are using to serve the application. Something like this maybe:

    <script type="text/javascript">
        scriptsRoot = '${applicationHome}/js';
    </script>

    <script type="text/javascript" src="${applicationHome}/js/loaderConfig.js"></script>
    <script type="text/javascript" src="${applicationHome}/js/app.js"></script>

And when use requires (or uses) config you should always use full name (e.g. AMC.overrides.whatever.ClassName).

Upvotes: 0

SAnDAnGE
SAnDAnGE

Reputation: 428

I also got into this problem, because I am using grunt-filerev

This is the best solution I got so far:

/**
 * Override for Ext.Loader.getPath using Interceptor
 * @return {string} The path after the build process
 */
(function() {
    var method = Ext.Loader.getPath;
    Ext.Loader.getPath = function() {
        var path = method.apply(this, arguments);
        return my.bootstrap.assets[path] || path;
    };
})();

Upvotes: 1

Related Questions