Changeset 717
- Timestamp:
- 04/24/06 12:53:58 (2 years ago)
- Files:
-
- mochikit/trunk/MochiKit/Async.js (modified) (2 diffs)
- mochikit/trunk/MochiKit/Base.js (modified) (6 diffs)
- mochikit/trunk/MochiKit/Iter.js (modified) (17 diffs)
- mochikit/trunk/MochiKit/Logging.js (modified) (1 diff)
- mochikit/trunk/doc/html/MochiKit/Base.html (modified) (4 diffs)
- mochikit/trunk/doc/html/MochiKit/VersionHistory.html (modified) (1 diff)
- mochikit/trunk/doc/html/MochiKit/index.html (modified) (1 diff)
- mochikit/trunk/doc/rst/MochiKit/Base.rst (modified) (4 diffs)
- mochikit/trunk/doc/rst/MochiKit/VersionHistory.rst (modified) (1 diff)
- mochikit/trunk/packed/MochiKit/MochiKit.js (modified) (25 diffs)
- mochikit/trunk/tests/test_Base.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
mochikit/trunk/MochiKit/Async.js
r662 r717 148 148 }, 149 149 150 toString: MochiKit.Base.forward ("repr"),150 toString: MochiKit.Base.forwardCall("repr"), 151 151 152 152 _nextId: MochiKit.Base.counter(), … … 624 624 return 'DeferredLock(' + this.id + ', ' + state + ')'; 625 625 }, 626 toString: MochiKit.Base.forward ("repr")626 toString: MochiKit.Base.forwardCall("repr") 627 627 628 628 }; mochikit/trunk/MochiKit/Base.js
r714 r717 277 277 }, 278 278 279 forward : function (func) {279 forwardCall: function (func) { 280 280 /*** 281 281 … … 1086 1086 }, 1087 1087 1088 find : function (lst, value, start/* = 0 */, /* optional */end) {1088 findValue: function (lst, value, start/* = 0 */, /* optional */end) { 1089 1089 if (typeof(end) == "undefined" || end == null) { 1090 1090 end = lst.length; … … 1289 1289 "NamedError", 1290 1290 "operator", 1291 "forward ",1291 "forwardCall", 1292 1292 "itemgetter", 1293 1293 "typeMatcher", … … 1331 1331 "evalJSON", 1332 1332 "parseQueryString", 1333 "find ",1333 "findValue", 1334 1334 "findIdentical", 1335 1335 "flattenArguments" … … 1366 1366 // A singleton raised when no suitable adapter is found 1367 1367 var m = this; 1368 1369 // Backwards compat 1370 m.forward = m.forwardCall; 1371 m.find = m.findValue; 1372 1368 1373 if (typeof(encodeURIComponent) != "undefined") { 1369 1374 m.urlEncode = function (unencoded) { … … 1392 1397 } 1393 1398 }, 1394 toString: m.forward ("repr")1399 toString: m.forwardCall("repr") 1395 1400 }); 1396 1401 mochikit/trunk/MochiKit/Iter.js
r555 r717 126 126 return { 127 127 repr: function () { return "count(" + n + ")"; }, 128 toString: m.forward ("repr"),128 toString: m.forwardCall("repr"), 129 129 next: m.counter(n) 130 130 }; … … 143 143 return { 144 144 repr: function () { return "cycle(...)"; }, 145 toString: m.forward ("repr"),145 toString: m.forwardCall("repr"), 146 146 next: function () { 147 147 try { … … 183 183 return "repeat(" + m.repr(elem) + ")"; 184 184 }, 185 toString: m.forward ("repr"),185 toString: m.forwardCall("repr"), 186 186 next: function () { 187 187 return elem; … … 193 193 return "repeat(" + m.repr(elem) + ", " + n + ")"; 194 194 }, 195 toString: m.forward ("repr"),195 toString: m.forwardCall("repr"), 196 196 next: function () { 197 197 if (n <= 0) { … … 224 224 return { 225 225 repr: function () { return "izip(...)"; }, 226 toString: m.forward ("repr"),226 toString: m.forwardCall("repr"), 227 227 next: function () { return m.map(next, iterables); } 228 228 }; … … 242 242 return { 243 243 repr: function () { return "ifilter(...)"; }, 244 toString: m.forward ("repr"),244 toString: m.forwardCall("repr"), 245 245 next: function () { 246 246 while (true) { … … 270 270 return { 271 271 repr: function () { return "ifilterfalse(...)"; }, 272 toString: m.forward ("repr"),272 toString: m.forwardCall("repr"), 273 273 next: function () { 274 274 while (true) { … … 312 312 return "islice(" + ["...", start, stop, step].join(", ") + ")"; 313 313 }, 314 toString: m.forward ("repr"),314 toString: m.forwardCall("repr"), 315 315 next: function () { 316 316 var rval; … … 341 341 return { 342 342 repr: function () { return "imap(...)"; }, 343 toString: m.forward ("repr"),343 toString: m.forwardCall("repr"), 344 344 next: function () { 345 345 return fun.apply(this, map(next, iterables)); … … 359 359 return { 360 360 repr: function () { return "applymap(...)"; }, 361 toString: m.forward ("repr"),361 toString: m.forwardCall("repr"), 362 362 next: function () { 363 363 return fun.apply(self, seq.next()); … … 381 381 return { 382 382 repr: function () { return "chain(...)"; }, 383 toString: m.forward ("repr"),383 toString: m.forwardCall("repr"), 384 384 next: function () { 385 385 while (argiter.length > 1) { … … 415 415 return { 416 416 repr: function () { return "takewhile(...)"; }, 417 toString: MochiKit.Base.forward ("repr"),417 toString: MochiKit.Base.forwardCall("repr"), 418 418 next: function () { 419 419 var rval = seq.next(); … … 441 441 return { 442 442 "repr": function () { return "dropwhile(...)"; }, 443 "toString": m.forward ("repr"),443 "toString": m.forwardCall("repr"), 444 444 "next": function () { 445 445 while (true) { … … 461 461 return { 462 462 repr: function () { return "tee(" + ident + ", ...)"; }, 463 toString: m.forward ("repr"),463 toString: m.forwardCall("repr"), 464 464 next: function () { 465 465 var rval; … … 639 639 return "range(" + [start, stop, step].join(", ") + ")"; 640 640 }, 641 toString: MochiKit.Base.forward ("repr")641 toString: MochiKit.Base.forwardCall("repr") 642 642 }; 643 643 }, … … 908 908 return { 909 909 repr: function () { return "arrayLikeIter(...)"; }, 910 toString: MochiKit.Base.forward ("repr"),910 toString: MochiKit.Base.forwardCall("repr"), 911 911 next: function () { 912 912 if (i >= iterable.length) { … … 925 925 return { 926 926 repr: function () { return "iterateNextIter(...)"; }, 927 toString: MochiKit.Base.forward ("repr"),927 toString: MochiKit.Base.forwardCall("repr"), 928 928 next: function () { 929 929 var rval = iterable.iterateNext(); mochikit/trunk/MochiKit/Logging.js
r674 r717 77 77 ).join(', ') + ')'; 78 78 }, 79 toString: MochiKit.Base.forward ("repr")79 toString: MochiKit.Base.forwardCall("repr") 80 80 }; 81 81 mochikit/trunk/doc/html/MochiKit/Base.html
r714 r717 459 459 </blockquote> 460 460 <p> 461 <a name="fn-find "></a>462 <a class="mochidef reference" href="#fn-find ">find(lst, value, start=0, end=lst.length)</a>:</p>461 <a name="fn-findvalue"></a> 462 <a class="mochidef reference" href="#fn-findvalue">findValue(lst, value, start=0, end=lst.length)</a>:</p> 463 463 <blockquote> 464 464 <p>Finds the index of <tt class="docutils literal"><span class="pre">value</span></tt> in the <tt class="docutils literal"><span class="pre">Array</span></tt>-like object <tt class="docutils literal"><span class="pre">lst</span></tt> using … … 468 468 <p>For example:</p> 469 469 <pre class="literal-block"> 470 assert( find ([1, 2, 3, 2, 1], 2) == 1 )471 assert( find ([1, 2, 3, 2, 1], 2, 2) == 3 )470 assert( findValue([1, 2, 3, 2, 1], 2) == 1 ) 471 assert( findValue([1, 2, 3, 2, 1], 2, 2) == 3 ) 472 472 </pre> 473 473 </blockquote> … … 480 480 at the index <tt class="docutils literal"><span class="pre">end</span> <span class="pre">-</span> <span class="pre">1</span></tt>. If <tt class="docutils literal"><span class="pre">value</span></tt> is not found in <tt class="docutils literal"><span class="pre">lst</span></tt>, it will 481 481 return <tt class="docutils literal"><span class="pre">-1</span></tt>.</p> 482 <p>You should use this function instead of <a class="mochiref reference" href="#fn-find ">find</a> if <tt class="docutils literal"><span class="pre">lst</span></tt> may482 <p>You should use this function instead of <a class="mochiref reference" href="#fn-findvalue">findValue</a> if <tt class="docutils literal"><span class="pre">lst</span></tt> may 483 483 be comprised of objects for which no comparator is defined and all you care 484 484 about is finding an identical object (e.g. the same instance), or if … … 503 503 </blockquote> 504 504 <p> 505 <a name="fn-forward "></a>506 <a class="mochidef reference" href="#fn-forward ">forward(name)</a>:</p>505 <a name="fn-forwardcall"></a> 506 <a class="mochidef reference" href="#fn-forwardcall">forwardCall(name)</a>:</p> 507 507 <blockquote> 508 508 Returns a function that forwards a method call to <tt class="docutils literal"><span class="pre">this.name(...)</span></tt></blockquote> mochikit/trunk/doc/html/MochiKit/VersionHistory.html
r714 r717 16 16 <p>2006-04-XX v1.3 "warp zone"</p> 17 17 <ul class="simple"> 18 <li>IMPORTANT: Renamed MochiKit.Base.forward to forwardCall (for export)</li> 19 <li>IMPORTANT: Renamed MochiKit.Base.find to findValue (for export)</li> 18 20 <li>New MochiKit.Base.flattenArguments for flattening a list of arguments to 19 21 a single Array</li> mochikit/trunk/doc/html/MochiKit/index.html
r714 r717 55 55 <p>2006-04-XX v1.3 "warp zone"</p> 56 56 <ul class="simple"> 57 <li>IMPORTANT: Renamed MochiKit.Base.forward to forwardCall (for export)</li> 58 <li>IMPORTANT: Renamed MochiKit.Base.find to findValue (for export)</li> 57 59 <li>New MochiKit.Base.flattenArguments for flattening a list of arguments to 58 60 a single Array</li> mochikit/trunk/doc/rst/MochiKit/Base.rst
r714 r717 474 474 475 475 476 :mochidef:`find (lst, value, start=0, end=lst.length)`:476 :mochidef:`findValue(lst, value, start=0, end=lst.length)`: 477 477 478 478 Finds the index of ``value`` in the ``Array``-like object ``lst`` using … … 483 483 For example:: 484 484 485 assert( find ([1, 2, 3, 2, 1], 2) == 1 )486 assert( find ([1, 2, 3, 2, 1], 2, 2) == 3 )485 assert( findValue([1, 2, 3, 2, 1], 2) == 1 ) 486 assert( findValue([1, 2, 3, 2, 1], 2, 2) == 3 ) 487 487 488 488 … … 494 494 return ``-1``. 495 495 496 You should use this function instead of :mochiref:`find ` if ``lst`` may496 You should use this function instead of :mochiref:`findValue` if ``lst`` may 497 497 be comprised of objects for which no comparator is defined and all you care 498 498 about is finding an identical object (e.g. the same instance), or if … … 515 515 516 516 517 :mochidef:`forward (name)`:517 :mochidef:`forwardCall(name)`: 518 518 519 519 Returns a function that forwards a method call to ``this.name(...)`` mochikit/trunk/doc/rst/MochiKit/VersionHistory.rst
r714 r717 1 1 2006-04-XX v1.3 "warp zone" 2 2 3 - IMPORTANT: Renamed MochiKit.Base.forward to forwardCall (for export) 4 - IMPORTANT: Renamed MochiKit.Base.find to findValue (for export) 3 5 - New MochiKit.Base.flattenArguments for flattening a list of arguments to 4 6 a single Array mochikit/trunk/packed/MochiKit/MochiKit.js
r714 r717 207 207 },contains:function(a,b){ 208 208 return b in a; 209 }},forward :function(_30){209 }},forwardCall:function(_30){ 210 210 return function(){ 211 211 return this[_30].apply(this,arguments); … … 689 689 } 690 690 return -1; 691 },find :function(lst,_101,_102,end){691 },findValue:function(lst,_101,_102,end){ 692 692 if(typeof (end)=="undefined"||end==null){ 693 693 end=lst.length; … … 810 810 return false; 811 811 }}; 812 MochiKit.Base.EXPORT=["counter","clone","extend","update","updatetree","setdefault","keys","items","NamedError","operator","forward ","itemgetter","typeMatcher","isCallable","isUndefined","isUndefinedOrNull","isNull","isNotEmpty","isArrayLike","isDateLike","xmap","map","xfilter","filter","bind","bindMethods","NotFound","AdapterRegistry","registerComparator","compare","registerRepr","repr","objEqual","arrayEqual","concat","keyComparator","reverseKeyComparator","partial","merge","listMinMax","listMax","listMin","objMax","objMin","nodeWalk","zip","urlEncode","queryString","serializeJSON","registerJSON","evalJSON","parseQueryString","find","findIdentical","flattenArguments"];812 MochiKit.Base.EXPORT=["counter","clone","extend","update","updatetree","setdefault","keys","items","NamedError","operator","forwardCall","itemgetter","typeMatcher","isCallable","isUndefined","isUndefinedOrNull","isNull","isNotEmpty","isArrayLike","isDateLike","xmap","map","xfilter","filter","bind","bindMethods","NotFound","AdapterRegistry","registerComparator","compare","registerRepr","repr","objEqual","arrayEqual","concat","keyComparator","reverseKeyComparator","partial","merge","listMinMax","listMax","listMin","objMax","objMin","nodeWalk","zip","urlEncode","queryString","serializeJSON","registerJSON","evalJSON","parseQueryString","findValue","findIdentical","flattenArguments"]; 813 813 MochiKit.Base.EXPORT_OK=["nameFunctions","comparatorRegistry","reprRegistry","jsonRegistry","compareDateLike","compareArrayLike","reprArrayLike","reprString","reprNumber"]; 814 814 MochiKit.Base._exportSymbols=function(_124,_125){ … … 826 826 MochiKit.Base.__new__=function(){ 827 827 var m=this; 828 m.forward=m.forwardCall; 829 m.find=m.findValue; 828 830 if(typeof (encodeURIComponent)!="undefined"){ 829 831 m.urlEncode=function(_127){ … … 846 848 return this.name+"()"; 847 849 } 848 },toString:m.forward ("repr")});850 },toString:m.forwardCall("repr")}); 849 851 m.NotFound=new m.NamedError("MochiKit.Base.NotFound"); 850 852 m.listMax=m.partial(m.listMinMax,1); … … 926 928 return {repr:function(){ 927 929 return "count("+n+")"; 928 },toString:m.forward ("repr"),next:m.counter(n)};930 },toString:m.forwardCall("repr"),next:m.counter(n)}; 929 931 },cycle:function(p){ 930 932 var self=MochiKit.Iter; … … 934 936 return {repr:function(){ 935 937 return "cycle(...)"; 936 },toString:m.forward ("repr"),next:function(){938 },toString:m.forwardCall("repr"),next:function(){ 937 939 try{ 938 940 var rval=_136.next(); … … 963 965 return {repr:function(){ 964 966 return "repeat("+m.repr(elem)+")"; 965 },toString:m.forward ("repr"),next:function(){967 },toString:m.forwardCall("repr"),next:function(){ 966 968 return elem; 967 969 }}; … … 969 971 return {repr:function(){ 970 972 return "repeat("+m.repr(elem)+", "+n+")"; 971 },toString:m.forward ("repr"),next:function(){973 },toString:m.forwardCall("repr"),next:function(){ 972 974 if(n<=0){ 973 975 throw MochiKit.Iter.StopIteration; … … 984 986 return {repr:function(){ 985 987 return "izip(...)"; 986 },toString:m.forward ("repr"),next:function(){988 },toString:m.forwardCall("repr"),next:function(){ 987 989 return m.map(next,_141); 988 990 }}; … … 995 997 return {repr:function(){ 996 998 return "ifilter(...)"; 997 },toString:m.forward ("repr"),next:function(){999 },toString:m.forwardCall("repr"),next:function(){ 998 1000 while(true){ 999 1001 var rval=seq.next(); … … 1012 1014 return {repr:function(){ 1013 1015 return "ifilterfalse(...)"; 1014 },toString:m.forward ("repr"),next:function(){1016 },toString:m.forwardCall("repr"),next:function(){ 1015 1017 while(true){ 1016 1018 var rval=seq.next(); … … 1043 1045 return {repr:function(){ 1044 1046 return "islice("+["...",_144,stop,step].join(", ")+")"; 1045 },toString:m.forward ("repr"),next:function(){1047 },toString:m.forwardCall("repr"),next:function(){ 1046 1048 var rval; 1047 1049 while(i<_144){ … … 1063 1065 return {repr:function(){ 1064 1066 return "imap(...)"; 1065 },toString:m.forward ("repr"),next:function(){1067 },toString:m.forwardCall("repr"),next:function(){ 1066 1068 return fun.apply(this,map(next,_148)); 1067 1069 }}; … … 1071 1073 return {repr:function(){ 1072 1074 return "applymap(...)"; 1073 },toString:m.forward ("repr"),next:function(){1075 },toString:m.forwardCall("repr"),next:function(){ 1074 1076 return fun.apply(self,seq.next()); 1075 1077 }}; … … 1083 1085 return {repr:function(){ 1084 1086 return "chain(...)"; 1085 },toString:m.forward ("repr"),next:function(){1087 },toString:m.forwardCall("repr"),next:function(){ 1086 1088 while(_150.length>1){ 1087 1089 try{ … … 1107 1109 return {repr:function(){ 1108 1110 return "takewhile(...)"; 1109 },toString:MochiKit.Base.forward ("repr"),next:function(){1111 },toString:MochiKit.Base.forwardCall("repr"),next:function(){ 1110 1112 var rval=seq.next(); 1111 1113 if(!pred(rval)){ … … 1123 1125 return {"repr":function(){ 1124 1126 return "dropwhile(...)"; 1125 },"toString":m.forward ("repr"),"next":function(){1127 },"toString":m.forwardCall("repr"),"next":function(){ 1126 1128 while(true){ 1127 1129 var rval=seq.next(); … … 1139 1141 return {repr:function(){ 1140 1142 return "tee("+_152+", ...)"; 1141 },toString:m.forward ("repr"),next:function(){1143 },toString:m.forwardCall("repr"),next:function(){ 1142 1144 var rval; 1143 1145 var i=sync.pos[_152]; … … 1254 1256 },repr:function(){ 1255 1257 return "range("+[_162,stop,step].join(", ")+")"; 1256 },toString:MochiKit.Base.forward ("repr")};1258 },toString:MochiKit.Base.forwardCall("repr")}; 1257 1259 },sum:function(_163,_164){ 1258 1260 var x=_164||0; … … 1433 1435 return {repr:function(){ 1434 1436 return "arrayLikeIter(...)"; 1435 },toString:MochiKit.Base.forward ("repr"),next:function(){1437 },toString:MochiKit.Base.forwardCall("repr"),next:function(){ 1436 1438 if(i>=_185.length){ 1437 1439 throw MochiKit.Iter.StopIteration; … … 1444 1446 return {repr:function(){ 1445 1447 return "iterateNextIter(...)"; 1446 },toString:MochiKit.Base.forward ("repr"),next:function(){1448 },toString:MochiKit.Base.forwardCall("repr"),next:function(){ 1447 1449 var rval=_187.iterateNext(); 1448 1450 if(rval===null||rval===undefined){ … … 1503 1505 var m=MochiKit.Base; 1504 1506 return "LogMessage("+m.map(m.repr,[this.num,this.level,this.info]).join(", ")+")"; 1505 },toString:MochiKit.Base.forward ("repr")};1507 },toString:MochiKit.Base.forwardCall("repr")}; 1506 1508 MochiKit.Base.update(MochiKit.Logging,{logLevelAtLeast:function(_191){ 1507 1509 var self=MochiKit.Logging; … … 2072 2074 } 2073 2075 return "Deferred("+this.id+", "+_278+")"; 2074 },toString:MochiKit.Base.forward ("repr"),_nextId:MochiKit.Base.counter(),cancel:function(){2076 },toString:MochiKit.Base.forwardCall("repr"),_nextId:MochiKit.Base.counter(),cancel:function(){ 2075 2077 var self=MochiKit.Async; 2076 2078 if(this.fired==-1){ … … 2361 2363 } 2362 2364 return "DeferredLock("+this.id+", "+_300+")"; 2363 },toString:MochiKit.Base.forward ("repr")};2365 },toString:MochiKit.Base.forwardCall("repr")}; 2364 2366 MochiKit.Async.DeferredList=function(list,_302,_303,_304,_305){ 2365 2367 this.list=list; mochikit/trunk/tests/test_Base.js
r714 r717 377 377 t.is( c(), 3, "counter increases" ); 378 378 379 t.is( find ([1, 2, 3], 4), -1, "findreturns -1 on not found");380 t.is( find ([1, 2, 3], 1), 0, "findreturns correct index");381 t.is( find ([1, 2, 3], 1, 1), -1, "findhonors start");382 t.is( find ([1, 2, 3], 2, 0, 1), -1, "findhonors end");379 t.is( findValue([1, 2, 3], 4), -1, "findValue returns -1 on not found"); 380 t.is( findValue([1, 2, 3], 1), 0, "findValue returns correct index"); 381 t.is( findValue([1, 2, 3], 1, 1), -1, "findValue honors start"); 382 t.is( findValue([1, 2, 3], 2, 0, 1), -1, "findValue honors end"); 383 383 t.is( findIdentical([1, 2, 3], 4), -1, "findIdentical returns -1"); 384 384 t.is( findIdentical([1, 2, 3], 1), 0, "findIdentical returns correct index");
