Results 1 to 2 of 2

Thread: Stratified ExtDirect

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sencha User khebs@live.com's Avatar
    Join Date
    Mar 2008
    Posts
    83
    Vote Rating
    0
      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,318
    Vote Rating
    1291
      0  

    Default

    The addProvider should really be within your onReady or launch method of Ext.application
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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 in print!

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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •