1. #1
    Sencha User khebs@live.com's Avatar
    Join Date
    Mar 2008
    Posts
    83
    Vote Rating
    0
    khebs@live.com is on a distinguished road

      0  

    Default Stratified ExtDirect

    Stratified ExtDirect


    Code:
    exports.stratified = function(namespace, descriptor) {
        try {
            var _d = eval(descriptor);
            var _n = eval(namespace);
            var _a = _d['actions'];
    
            console.log(_n);
    
            for (action in _a) {
                
                exports[action] = {}
    
                for (fnc in _a[action]) {
                    var name = _a[action][fnc].name, // function name
                        params = [], 
                        len = _a[action][fnc].len; // parameter count
    
                    exports[action][name] = {};
    
                    // create parameters
                    //
                    for (var i = 0; i < len; i++) params.push('_'+i);
    
                    // create syntax
                    //
                    var sfn = [
                        '(function(){ return function(', params.join(', '), '){',
                            'var res = null; ',
                            'waitfor() { ',
                                'var r = resume;',
                                namespace, '.', action, '.', name, 
                                    '(', (params.length>0?(params.join(', ')+', '):''), 'function(sr){ res = sr; r(); }); ',
                            '}',
                            'return res; ',
                        '} })();',
                    ].join('');
    
                    //console.log(sfn);
                    
                    var js = __oni_rt.c1.compile(sfn, { filename: "DirectSyncConvertCode" });
                    exports[action][name] = __oni_rt.G.eval(js);
                }
            }
    
            return this;
        } 
        catch(e) 
        {
            console.error(e);
            /* Do nothing! */
        }
    };
    USAGE:

    Code:
        var sRPC = require('utils/rpc').stratified('RPC.Api', 'RPC.Descriptor');
        console.log("Server Time: " + sRPC.Server.date('y-m-d G:i a'));
    EXTDIRECT OUTPUT:

    Code:
    Ext.namespace( 'RPC.Api' );
    RPC.Descriptor = {"url":"\/App\/public\/direct","type":"remoting","namespace":"RPC.Api","descriptor":"RPC.Descriptor","actions":{"Server":[{"name":"date","len":1}],"User":[{"name":"login","len":2}]}};
    Ext.Direct.addProvider( RPC.Descriptor );

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,599
    Vote Rating
    435
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    The addProvider should really be within your onReady or launch method of Ext.application
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!

    When posting code, please use BBCode's CODE tags.

Tags for this Thread