Changeset 7988

Show
Ignore:
Timestamp:
04/07/07 15:51:40 (20 months ago)
Author:
sjmiles
Message:

First draft of new connect/event stuff. Refs #2641

Location:
dojo/trunk
Files:
3 added
6 modified

Legend:

Unmodified
Added
Removed
  • dojo/trunk/tests/_base.js

    r7973 r7988  
    119119        dojo.require("tests._base.lang"); 
    120120        dojo.require("tests._base.declare"); 
     121        dojo.require("tests._base.connect"); 
    121122        dojo.require("tests._base.Deferred"); 
    122123        dojo.require("tests._base.json"); 
  • dojo/trunk/tests/_base/declare.js

    r7917 r7988  
    161161                                        }, 
    162162                                        baz: function(arg1, arg2){ 
    163                                                 this.inherited("bar", arguments); 
     163                                                //this.inherited("baz", arguments); 
     164                                                this.inherited("bar", arguments, tests._base.declare.tmp15.prototype.bar); 
    164165                                        } 
    165166                                } 
  • dojo/trunk/_base.js

    r7980 r7988  
    11dojo.require("dojo._base.lang"); 
    22dojo.require("dojo._base.declare"); 
     3dojo.require("dojo._base.connect"); 
    34dojo.require("dojo._base.Deferred"); 
    45dojo.require("dojo._base.json"); 
    56dojo.require("dojo._base.array"); 
    67// dojo.requireIf(dojo.isBrowser, "dojo._base.browserConnect"); 
    7 // dojo.requireIf(dojo, "dojo._base.connect"); 
     8dojo.requireIf(dojo.isBrowser, "dojo._base.event"); 
    89dojo.requireIf(dojo.isBrowser, "dojo._base.html"); 
    910dojo.requireIf(dojo.isBrowser, "dojo._base.NodeList"); 
  • dojo/trunk/_base/declare.js

    r7917 r7988  
    2727        //              prototype extension.  
    2828        // 
    29         //              All "superclass(es)" must be Functions (not mere Objects). 
     29        //              All superclasses (including mixins) must be Functions (not simple Objects). 
    3030        // 
    3131        //              Mixin ancestors provide a type of multiple inheritance. 
    32         //              The prototypical properties of mixin ancestors are copied  
    33         //              to the subclass.  
     32        //       
     33        //              Prototypes of mixin ancestors are copied to the new class. 
    3434        // 
    35         //              name of the class ("className" argument) is stored in 
    36         //              "declaredClass" property 
    37         //  
    38         //              Aliased as "dojo.declare" 
     35        //              "className" is cached in "declaredClass" property of the new class. 
    3936        // 
    4037        // usage: 
     
    8784        ctor.mixins = mixins; 
    8885        // copy the mixin prototype to the new prototype 
    89         dojo.forEach(mixins, function(i){ 
    90                 dojo.extend(ctor, i.prototype); 
    91         }); 
    92         /* 
    93         for(var i=0,l=mixins.length; i<l; i++){ 
    94                 dojo.extend(ctor, mixins[i].prototype); 
     86        for(var i=0,m;(m=mixins[i]);i++){ 
     87                dojo.extend(ctor, m.prototype); 
    9588        } 
    96         */ 
    9789        // 
    9890        // V. Finalize constructor 
     
    111103        // 
    112104        // VI. Create named reference 
    113         // with(dojo.getProp(className, true)){obj[prop] = ctor;} 
    114         var pcn = className.split("."); var oname = pcn.pop(); pcn = pcn.join("."); 
    115         var prt = (pcn.length) ? dojo.getObject(pcn, true) : dojo.global(); 
    116         prt[oname] = ctor; 
    117         return ctor; // Function 
     105        return dojo.setObject(className, ctor); // Function 
    118106} 
    119107 
     
    125113                // initialize any mixins 
    126114                if(c.mixins){ 
    127                         // FIXME: why mp? 
    128                         for(var i=0, m, mp; (m=c.mixins[i])&&(mp=m.prototype); i++){ 
    129                                 (mp.initializer||m).apply(this, arguments); 
     115                        for(var i=0, m, f; (m=c.mixins[i]); i++){ 
     116                                // avoid the constructor on 'declared' mixins 
     117                                (f=("initializer" in m ? m.initializer : m))&&(f.apply(this, arguments)); 
    130118                        } 
    131119                } 
     
    140128        _findInherited: function(name, callee){ 
    141129                var p = this.constructor.prototype; 
    142                 var lp; 
    143                 if(this[name] !== callee){ 
    144                         while(p && (p[name] !== callee)){  
    145                                 lp = p; 
    146                                 p = p.constructor.superclass; 
     130                if (this[name]!==callee){ 
     131                        while(p && (p[name]!==callee)){  
     132                                p = p.constructor.superclass;  
    147133                        } 
    148                         p = lp; 
    149134                } 
    150                 while(p && (p[name] === callee)){  
    151                         p = p.constructor.superclass; 
     135                if ((!p)||(p[name]!==callee)){ 
     136                        throw(this.toString() + ': name argument ("' + name + '") to inherited does not match callee (declare.js)'); 
    152137                } 
    153                 return (p)&&(p[name]);           
     138                while(p && (p[name]===callee)){  
     139                        p = p.constructor.superclass;  
     140                } 
     141                return (p)&&(p[name]);   
    154142        }, 
    155143        inherited: function(name, args, callee){ 
  • dojo/trunk/_base/lang.js

    r7917 r7988  
    55dojo.isString = function(/*anything*/ it){ 
    66        // summary:     Return true if it is a String. 
    7  
    8         return (typeof it == "string" || it instanceof String); 
     7        return (typeof it == "string" || it instanceof String); // Boolean 
    98} 
    109 
    1110dojo.isArray = function(/*anything*/ it){ 
    1211        // summary: Return true of it is an Array 
    13  
    1412        return (it && it instanceof Array || typeof it == "array" || ((typeof dojo["NodeList"] != "undefined") && (it instanceof dojo.NodeList))); // Boolean 
    1513} 
     
    7270        } 
    7371        // IE doesn't recognize custom toStrings in for..in 
    74         if(     dojo.isIE &&  
     72        if(dojo.isIE &&  
    7573                (typeof(props["toString"]) == "function") &&  
    7674                (props["toString"] != obj["toString"]) &&  
     
    10199} 
    102100 
    103 dojo.hitch = function(/*Object*/thisObject, /*Function|String*/method /*, ...*/){ 
     101dojo._hitchArgs = function(scope, method /*,...*/){ 
     102        var pre = []; 
     103        for(var x=2; x<arguments.length; x++){ 
     104                pre.push(arguments[x]); 
     105        } 
     106        var named = dojo.isString(method); 
     107        return function(){ 
     108                // arrayify arguments 
     109                var args = []; 
     110                for(var x=0; x<arguments.length; x++){ 
     111                        args.push(arguments[x]); 
     112                } 
     113                // locate our method 
     114                var f = (named ? (scope||dojo.global())[method] : method); 
     115                // invoke with collected args 
     116                return (f)&&(f.apply(scope||this, pre.concat(args))); // Any 
     117        } // Function 
     118} 
     119 
     120dojo.hitch = function(/*Object*/scope, /*Function|String*/method /*,...*/){ 
    104121        // summary:  
    105         //              Returns a function that will only ever execute in the a given scope 
    106         //              (thisObject). This allows for easy use of object member functions 
     122        //              Returns a function that will only ever execute in the a given scope.  
     123        //              This allows for easy use of object member functions 
    107124        //              in callbacks and other places in which the "this" keyword may 
    108         //              otherwise not reference the expected scope. Any number of default 
    109         //              positional arguments may be passed as parameters beyond "method". 
     125        //              otherwise not reference the expected scope.  
     126        //              Any number of default positional arguments may be passed as parameters  
     127        //              beyond "method". 
    110128        //              Each of these values will be used to "placehold" (similar to curry) 
    111         //              for the hitched function. Note that the order of arguments may be 
    112         //              reversed in a future version. 
    113         // thisObject: the scope to run the method in 
     129        //              for the hitched function.  
     130        // scope:  
     131        //              The scope to run the method in 
    114132        // method: 
    115         //              a function to be "bound" to thisObject or the name of the method in 
    116         //              thisObject to be used as the basis for the binding 
     133        //              A function to be hitched to scope, or the name of the method in 
     134        //              scope to be hitched. 
    117135        // usage: 
    118136        //              dojo.hitch(foo, "bar")(); // runs foo.bar() in the scope of foo 
    119137        //              dojo.hitch(foo, myFunction); // returns a function that runs myFunction in the scope of foo 
    120  
    121         // FIXME: 
    122         //              should this be extended to "fixate" arguments in a manner similar 
    123         //              to dojo.curry, but without the default execution of curry()? 
    124         var args = []; 
    125         for(var x=2; x<arguments.length; x++){ 
    126                 args.push(arguments[x]); 
     138        if(arguments.length > 2){ 
     139                return dojo._hitchArgs.apply(dojo, arguments); 
     140        }else if(dojo.isString(method)){ 
     141                scope = scope || dojo.global(); 
     142                return function(){ return scope[method].apply(scope, arguments||[]); } 
     143        }else{ 
     144                return (!scope ? method : function(){ return method.apply(scope, arguments||[]); }); 
    127145        } 
    128         var fcn = ((dojo.isString(method)) ? (thisObject||dojo.global())[method] : method) || function(){}; 
    129         return function(){ 
    130                 var ta = args.concat([]); // make a copy 
    131                 for(var x=0; x<arguments.length; x++){ 
    132                         ta.push(arguments[x]); 
    133                 } 
    134                 return fcn.apply((thisObject||this), ta); // Function 
    135         }; 
    136146} 
    137147 
     
    152162        //              whatever the execution context eventually becomes. This is the 
    153163        //              functional equivalent of calling: 
    154         //                      dojo.hitch(null, funcName, ...); 
     164        //              dojo.hitch(null, funcName, ...); 
    155165        var args = [ null ]; 
    156166        for(var x=0; x<arguments.length; x++){ 
  • dojo/trunk/_base/_loader/bootstrap.js

    r7774 r7988  
    9999} 
    100100 
    101 dojo.getObject = function(/*String*/name, /*Boolean*/create, /*Object*/obj){ 
    102         // summary:  
    103         //              gets an object from a dot-separated string, such as "A.B.C" 
     101dojo._getProp = function(/*Array*/parts, /*Boolean*/create, /*Object*/context){ 
     102        var obj=context||dojo.global(); 
     103        for(var i=0, p; obj&&(p=parts[i]); i++){ 
     104                obj = (p in obj ? obj[p] : (create ? obj[p]={} : undefined)); 
     105        } 
     106        return obj; // Any 
     107} 
     108 
     109dojo.setObject = function(/*String*/name, /*Any*/value, /*Object*/context){ 
     110        // summary:  
     111        //              Set a property from a dot-separated string, such as "A.B.C" 
    104112        //      description:  
    105         //              useful for longer api chains where you have to test each object in 
    106         //              the chain 
     113        //              Useful for longer api chains where you have to test each object in 
     114        //              the chain, or when you have an object reference in string format. 
     115        //              Objects are created as needed along 'path'. 
    107116        //      name:    
    108         //              Path to an object, in the form "A.B.C". 
    109         //      obj: 
     117        //              Path to a property, in the form "A.B.C". 
     118        //      context: 
     119        //              Optional. Object to use as root of path. Defaults to 
     120        //              'dojo.global()'. Null may be passed. 
     121        var parts=name.split("."), p=parts.pop(), obj=dojo._getProp(parts, true, context); 
     122        return (obj && p ? (obj[p]=value) : undefined); // Any 
     123} 
     124 
     125dojo.getObject = function(/*String*/name, /*Boolean*/create, /*Object*/context){ 
     126        // summary:  
     127        //              Get a property from a dot-separated string, such as "A.B.C" 
     128        //      description:  
     129        //              Useful for longer api chains where you have to test each object in 
     130        //              the chain, or when you have an object reference in string format. 
     131        //      name:    
     132        //              Path to an property, in the form "A.B.C". 
     133        //      context: 
    110134        //              Optional. Object to use as root of path. Defaults to 
    111135        //              'dojo.global()'. Null may be passed. 
     
    113137        //              Optional. If true, Objects will be created at any point along the 
    114138        //              'path' that is undefined. 
    115         var tprop, tobj = obj||dojo.global(); 
    116         var parts=name.split("."), i=0, lobj, tmp, tname; 
    117         do{ 
    118                 lobj = tobj; 
    119                 tname = parts[i]; 
    120                 tmp = tobj[parts[i]]; 
    121                 if((create)&&(!tmp)){ 
    122                         tmp = tobj[parts[i]] = {}; 
    123                 } 
    124                 tobj = tmp; 
    125                 i++; 
    126         }while(i<parts.length && tobj); 
    127         return tobj; // Object 
     139        return dojo._getProp(name.split("."), create, context); // Any 
    128140} 
    129141 
     
    139151        //              Optional. Object to use as root of path. Defaults to 
    140152        //              'dojo.global()'. Null may be passed. 
    141         return (!!dojo.getObject(name, false, obj)); // Boolean 
     153        return Boolean(dojo.getObject(name, false, obj)); // Boolean 
    142154} 
    143155