-1

In respect of Extjs 4.1.x I was able to use custom/wrapper library to manipulation model, store, view, controller as well as other utilities. So my demand is to replace boiler plate of code through my custom/wrapper library. Regarding the code as bellow:-

var Lib = Lib || {
    $class      : 'Lib',
    $package    : 'Default',
    version     : '1.0.00',
    getName     : function(){
        return Lib.$class;
    },
    define      : function(name, config){
        return Ext.define(name, config);
    }   
};

is my custom library, right now I would like to replace the following code

Ext.define('Myapp.view.main.MainModel', {
    extend: 'Ext.app.ViewModel',
    alias: 'viewmodel.main',
    data: {
        name: 'Myapp'
    }
});

as bellow the replacement/wrapper of Extjs code:

Lib.define('Myapp.view.main.MainModel', {
    extend: 'Ext.app.ViewModel',
    alias: 'viewmodel.main',
    data: {
        name: 'Myapp'
    }
});

But here is the problem cause Sencha CMD 5.x build error where previous version of Sencha SDK, CMD support to use 3rd party library simply use it in index.html

<script id="extwrapper" type="text/javascript" src="Lib.js"></script

but latest Sencha CMD 5.x with Extjs 5.x occurred compilation error. Any way I would like to use custom/wrapper library instead of Extjs 5.x use directly. Do you have any hacks? While I tried by adding my customer/wrapper library in app.json as

"js": [
    {
        "path": "${ext.dir}/build/ext-all-rtl-debug.js"
    },
    {
        "path": "${ext.dir}/Lib.js",
        "bootstrap": true
    },
    {
        "path": "app.js",
        "bundle": true
    }
],

still its appear Sencha CMD 5.x build error. Any kind of reference does not support on className even java script closure/inline function. for example

Ext.define((function(){ return 'Myapp.view.main.MainModel';})(), {
    extend: 'Ext.app.ViewModel',
    alias: alias,
    data: {
        name: 'Myapp'
    }
});

on data it's support simple java script closure/inline function but no reference. for example

Ext.define( 'Myapp.view.main.MainModel', (function(){ 
    return {
        extend: 'Ext.app.ViewModel',
        alias: 'viewmodel.main',
        data: {
            name: 'Myapp'
        }
    }   
})());

even when I am going to use simple reference it does not work. for example

Ext.define( 'Myapp.view.main.MainModel', (function(){ 
    var data = {
        extend: 'Ext.app.ViewModel',
        alias: 'viewmodel.main',
        data: {
            name: 'Myapp'
        }
    };
    return  data;
})());

Build Failure for code as above I mentioned

Sencha Cmd v5.0.2.270
[INF] Processing Build Descriptor : default
[INF] Loading app json manifest...
[WRN] C1003: Unsupported Ext.define syntax (function does not return object lite
ral) -- g:\js\extjs\myapp\app\view\main\MainModel.js:1
[WRN] C1003: Unsupported Ext.define syntax (function does not return object lite
ral) -- g:\js\extjs\myapp\app\view\main\MainModel.js:1
[ERR] C2008: Requirement had no matching files (Myapp.view.main.MainModel) -- g:\j
s\extjs\myapp\app\view\main\Main.js:12:50
[ERR]
[ERR] BUILD FAILED
[ERR] com.sencha.exceptions.ExBuild: Failed to find any files for g:\js\extjs\my
app\app\view\main\Main.js::ClassRequire::Myapp.view.main.MainModel
[ERR]
[ERR] Total time: 7 seconds
[ERR] The following error occurred while executing this line:
g:\js\extjs\myapp\.sencha\app\build-impl.xml:376: The following error occurred whi
le executing this line:
g:\js\extjs\myapp\.sencha\app\init-impl.xml:292: com.sencha.exceptions.ExBuild: Fa
iled to find any files for g:\js\extjs\myapp\app\view\main\Main.js::ClassRequire::
Myapp.view.main.MainModel

Where is the problem? There was no restriction with Extjs 4.1.3 with previous version Sencha SDK/CMD. but why they added such type of feature?

By Extjs-4.1.3 I was able to write and compile as the code as bellow

Ext.define(Lib.view.getAbsView('V01I001001X01'), {
    extend      : 'Ext.form.Panel',
    alias       : Lib.app.getAlias('V01I001001X01'),
    id          : 'V01I001001X01'.toLowerCase(), 
    bodyStyle   : {
        background  : 'none'
    },
    defaults    : {        
        //TODO
    },
    initComponent: function() {
        var me     = this;
        //TODO
        me.callParent(arguments);
    }
});

Which one work as like as hard code as bellow

Ext.define('Myapp.view.m01001.m0i001.v01i001001.V01I001001X01'), {
    extend      : 'Ext.form.Panel',
    alias       : 'widget.v01i001001x01'
    id          : 'v01i001001x01',
    bodyStyle   : {
        background  : 'none'
    },
    defaults    : {        
        //TODO
    },
    initComponent: function() {
        var me     = this;
        //TODO
        me.callParent(arguments);
    }
});
Śhāhēēd
  • 1,812
  • 6
  • 23
  • 44
  • What's the Sencha Command build error you are seeing? By the way, this is horrible, I have no idea why you'd actually want to do this in a real-world scenario. – Colin Ramsay Dec 09 '14 at 10:06
  • I just edit the post to attach error log for your observation – Śhāhēēd Dec 09 '14 at 10:29
  • Have you thought about dropping Sencha Command usage? You can just include your scripts on web page or pack them with any other js minification tool. – Krzysztof Dec 11 '14 at 07:09

1 Answers1

0

Part of your problem is that Sencha Command does not just run JavaScript it also parses and compiles it in order to do a lot of "clever" stuff. This means that there are some restrictions on how your code should be formed. See:

http://www.sencha.com/forum/showthread.php?261509-Unsupported-Ext.define-syntax-%28function-does-not-return-object-literal%29

You have this code:

Ext.define( 'Myapp.view.main.MainModel', (function(){ 
    return {
        extend: 'Ext.app.ViewModel',
        alias: 'viewmodel.main',
        data: {
            name: 'Myapp'
        }
    }   
})());

Which it seems CMD is parsing and seeing the second argument as something other than an object literal (which makes sense since it's not, it's a function). Obviously the following would work:

Ext.define( 'Myapp.view.main.MainModel', {
        extend: 'Ext.app.ViewModel',
        alias: 'viewmodel.main',
        data: {
            name: 'Myapp'
        }
});

I don't understand why you would ever want to use the first form, it seems to have no advantage over the standard method of doing it. Either way though, it looks like you would be better trying to work with Ext JS and CMD rather than hacking around this issue.

Colin Ramsay
  • 16,086
  • 9
  • 52
  • 57
  • Because I would like to manipulate `className` and `data` as my business demand as well as reduce the `boiler plate of code`. @colinramsay what are you marking its just the different approach but my goal is in the top of my post. – Śhāhēēd Dec 09 '14 at 11:29
  • Your alternative approach does not let you do anything that Ext JS does not already provide - at least as far as I can see. If you were to provide a more detailed example of what you are trying to achieve then it might be clearer. – Colin Ramsay Dec 09 '14 at 11:50
  • So there is no doubt about my code and It is implemented with Extjs 4.1.3 as well as previous version of compiler. `Extjs 5.x` force us to obey their feature and it's cause bitter experience. We are freedom to write code we hate Sencha Extjs Team to restrict us such type of freedom to write code. – Śhāhēēd Dec 09 '14 at 12:22
  • I suggest you read the link I put in my answer, since that gives a potential workaround to your issue. It is a shame you have to express such anger towards the team that has created this software, May I also suggest that since you have obviously paid for a license for Ext JS you could open a support ticket to explain your situation? – Colin Ramsay Dec 09 '14 at 12:32