1. #1
    Ext User
    Join Date
    Oct 2007
    Posts
    15
    Vote Rating
    0
    rstuven is on a distinguished road

      0  

    Default Ext.ux.using

    Ext.ux.using


    As a C# developer, I'm accustomed to the using directive that brings types from other namespaces to the current scope, so I came up with a handy function for my Ext projects to emulate "using" at some extent:

    Code:
    Ext.ux.using(
        Ext.data,
        Ext.form,
        Ext.grid,
        Ext.ux.grid.filter,
        {ShortAlias: Ext.long.path.to.SomeVeryLongClassName},
    
    function(ns) {
     
        // Some code...
    
        var g = new ns.GridPanel();
        var r = new ns.JsonReader();
        var t = new ns.TextField();
        var f = new ns.GridFilter();
        var a = new ns.ShortAlias();
    
        // More code...
        
    });
    When it comes useful, I start the scripts with this declaration. I adopted the "ns" convention as a shorthand for "namespace".

    The code behind the using function is very simple:

    Code:
    Ext.ux.using = function() {
    
        var ns = {};
        var upper = arguments.length - 1;
        
        for (var i = 0; i < upper; i++) {
            var source = arguments[i];
            Ext.apply(ns, source);
        }
        
        arguments[upper](ns);
    };
    I hope you find this tip useful
    Last edited by rstuven; 30 Oct 2007 at 5:00 PM. Reason: Grammar

  2. #2
    Sencha Premium Member andrei.neculau's Avatar
    Join Date
    Jul 2007
    Location
    Sweden
    Posts
    197
    Vote Rating
    0
    andrei.neculau is on a distinguished road

      0  

    Default


    I'm having difficulties following your code.

    So basically.. what you are doing is to apply procedures and properties from different namespaces to one namespace, thus merging them.

    Why would that be any good? Can you give a practical example?

  3. #3
    Ext User
    Join Date
    Oct 2007
    Posts
    15
    Vote Rating
    0
    rstuven is on a distinguished road

      0  

    Default


    Yes, it's as simple as you put it: merging different namespaces to one.

    The benefits are the same of the C# using directive (see link above) or import in Java and Python, or similar constructs in other languages: less typing in a structured way.

    A pratical example? See how is used the xg variable in the official Grid3 example. That's the intent.

  4. #4
    Sencha Premium Member andrei.neculau's Avatar
    Join Date
    Jul 2007
    Location
    Sweden
    Posts
    197
    Vote Rating
    0
    andrei.neculau is on a distinguished road

      0  

    Default


    I'm sorry to say that namespaces do have their purpose, while you are taking away that purpose. Just my opinion - open to debate on a very practical and useful example.

    xg in the Grid3 example is only a shortcut to Ext.grid, which thus has no connection to your idea.

  5. #5
    Ext User
    Join Date
    Aug 2007
    Posts
    204
    Vote Rating
    0
    DragonFist is on a distinguished road

      0  

    Default


    @andrei.neculau

    I cannot agree with you there. He's taking nothing away from the purpose of Namespaces AND what he is specifically doing is giving an easy way to create shortcuts to those namespaces.

  6. #6
    Sencha Premium Member andrei.neculau's Avatar
    Join Date
    Jul 2007
    Location
    Sweden
    Posts
    197
    Vote Rating
    0
    andrei.neculau is on a distinguished road

      0  

    Default


    I was open to debate on a practical example, but instead I will explain my view on what it has already been written.

    Code:
    Ext.ux.using(
        Ext.data,
        Ext.form,
        Ext.grid,
        Ext.ux.form,
        Ext.ux.grid.filter,
        {ShortAlias: Ext.long.path.to.SomeVeryLongClassName},
    
    function(ns) {
     
        // Some code...
    
        var g = new ns.GridPanel();
        var r = new ns.JsonReader();
        var t = new ns.TextField();
        var f = new ns.GridFilter();
        var a = new ns.ShortAlias();
    
        // More code...
        
    });
    First of all, I added Ext.ux.form (which we suppose to have Ext.ux.form.ComboBox) which would overwrite Ext.form.ComboBox - of course it would only happen if we are not paying attention, etc.

    Secondly, that code is only a rewrite of the following:
    Code:
    (function(){ 
        // Some code...
    
        var g = new Ext.grid.GridPanel();
        var r = new Ext.data.JsonReader();
        var t = new Ext.form.TextField();
        var f = new Ext.ux.grid.filter.GridFilter();
        var a = new Ext.long.path.to.SomeVeryLongClassName();
    
        // More code...
    })();
    Which would all be resumed by shortcuts to
    Code:
    // code...
    
    var EG = Ext.grid;
    var ED = Ext.data;
    var EF = Ext.form;
    var uEF = Ext.ux.form;
    var uEG = Ext.ux.grid;
    var uAlias = Ext.long.path.to;
    
    // code...
    
    (function(){ 
         // Some code...
     
        var g = new EG.GridPanel();
         var r = new ED.JsonReader();
         var t = new EF.TextField();
         var f = new uEG.filter.GridFilter();
         var a = new uAlias.SomeVeryLongClassName();
     
         // More code...
    })();
    I don't know - my organizing-focused mind will always keep to separate namespaces. Suite yourself if you find this useful.

  7. #7
    Sencha User
    Join Date
    Mar 2007
    Posts
    22
    Vote Rating
    0
    jakeonthenet is on a distinguished road

      0  

    Default


    andrei,

    Even though you don't see it, his extention is doing the exact same thing as your shortcut example.

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi