Checkpoint on module refactor.
authordsc <david.schoonover@gmail.com>
Sat, 27 Nov 2010 23:03:53 +0000 (15:03 -0800)
committerdsc <david.schoonover@gmail.com>
Sat, 27 Nov 2010 23:03:53 +0000 (15:03 -0800)
64 files changed:
src/Y/_intro.js [deleted file]
src/Y/_outro.js [deleted file]
src/Y/alias.cjs [moved from src/Y/alias.js with 81% similarity]
src/Y/class.cjs [moved from src/Y/y-class.js with 91% similarity]
src/Y/core.cjs [moved from src/Y/core.js with 75% similarity]
src/Y/index.cjs [new file with mode: 0644]
src/Y/op.cjs [moved from src/Y/y-op.js with 86% similarity]
src/Y/tofunction.cjs [moved from src/Y/to-function.js with 100% similarity]
src/Y/type.cjs [moved from src/Y/type.js with 62% similarity]
src/Y/types/array.cjs [moved from src/Y/y-array.js with 78% similarity]
src/Y/types/collection.cjs [moved from src/Y/y-collection.js with 91% similarity]
src/Y/types/function.cjs [moved from src/Y/y-function.js with 67% similarity]
src/Y/types/number.cjs [moved from src/Y/y-number.js with 75% similarity]
src/Y/types/object.cjs [moved from src/Y/y-object.js with 95% similarity]
src/Y/types/string.cjs [moved from src/Y/y-string.js with 95% similarity]
src/Y/y.cjs [moved from src/Y/y-core.js with 68% similarity]
src/ezl/layer.js [moved from src/easel/layer.js with 100% similarity]
src/ezl/loop/cooldown.js [moved from src/easel/loop/cooldown.js with 100% similarity]
src/ezl/loop/eventloop.js [moved from src/easel/loop/eventloop.js with 100% similarity]
src/ezl/loop/fps.js [moved from src/easel/loop/fps.js with 100% similarity]
src/ezl/math/line.js [moved from src/easel/math/line.js with 100% similarity]
src/ezl/math/math.js [moved from src/easel/math/math.js with 100% similarity]
src/ezl/math/rect.cjs [new file with mode: 0644]
src/ezl/math/vec.js [moved from src/easel/math/vec.js with 100% similarity]
src/ezl/shape/circle.js [moved from src/easel/shape/circle.js with 100% similarity]
src/ezl/shape/line.js [moved from src/easel/shape/line.js with 100% similarity]
src/ezl/shape/polygon.js [moved from src/easel/shape/polygon.js with 100% similarity]
src/ezl/shape/rect.js [moved from src/easel/shape/rect.js with 100% similarity]
src/ezl/shape/shape.js [moved from src/easel/shape/shape.js with 100% similarity]
src/ezl/util/astar.js [moved from src/easel/util/astar.js with 100% similarity]
src/ezl/util/binaryheap.js [moved from src/easel/util/binaryheap.js with 100% similarity]
src/ezl/util/graph.js [moved from src/easel/util/graph.js with 100% similarity]
src/ezl/util/tree/pointquadtree.js [moved from src/easel/util/tree/pointquadtree.js with 100% similarity]
src/ezl/util/tree/quadtree.js [moved from src/easel/util/tree/quadtree.js with 100% similarity]
src/ezl/util/tree/rbtree.js [moved from src/easel/util/tree/rbtree.js with 100% similarity]
src/tanks/calc.cjs [moved from src/tanks/calc.js with 100% similarity]
src/tanks/config.cjs [new file with mode: 0644]
src/tanks/config.js [deleted file]
src/tanks/game.cjs [moved from src/tanks/game.js with 94% similarity]
src/tanks/globals.cjs [moved from src/tanks/globals.js with 99% similarity]
src/tanks/index.cjs [new file with mode: 0644]
src/tanks/map/index.cjs [new file with mode: 0644]
src/tanks/map/level.cjs [moved from src/tanks/map/level.js with 100% similarity]
src/tanks/map/loc/bbox.cjs [new file with mode: 0644]
src/tanks/map/loc/index.cjs [new file with mode: 0644]
src/tanks/map/loc/loc.cjs [moved from src/tanks/map/loc.js with 100% similarity]
src/tanks/map/loc/rect.cjs [new file with mode: 0644]
src/tanks/map/pathmap.cjs [moved from src/tanks/map/pathmap.js with 100% similarity]
src/tanks/map/trajectory.cjs [moved from src/tanks/map/trajectory.js with 100% similarity]
src/tanks/tanks.js [deleted file]
src/tanks/thing/bullet.cjs [moved from src/tanks/thing/bullet.js with 100% similarity]
src/tanks/thing/custom-tank.cjs [moved from src/tanks/thing/custom-tank.js with 100% similarity]
src/tanks/thing/index.cjs [new file with mode: 0644]
src/tanks/thing/player.cjs [moved from src/tanks/thing/player.js with 98% similarity]
src/tanks/thing/tank.cjs [moved from src/tanks/thing/tank.js with 100% similarity]
src/tanks/thing/thing.cjs [moved from src/tanks/thing/thing.js with 94% similarity]
src/tanks/ui/grid.cjs [moved from src/tanks/ui/grid.js with 100% similarity]
src/tanks/ui/index.cjs [new file with mode: 0644]
src/tanks/ui/main.cjs [moved from src/tanks/ui/main.js with 100% similarity]
src/tanks/ui/ui-config.cjs [moved from src/tanks/ui/ui-config.js with 100% similarity]
src/tanks/ui/ui.cjs [moved from src/tanks/ui/ui.js with 100% similarity]
src/tanks/util/config.cjs [moved from src/tanks/util/config.js with 100% similarity]
src/tanks/util/utils.cjs [moved from src/tanks/util/utils.js with 100% similarity]
tanks.php

diff --git a/src/Y/_intro.js b/src/Y/_intro.js
deleted file mode 100644 (file)
index 1fb369f..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-(function(){
-
-this.Y = Y;
-
diff --git a/src/Y/_outro.js b/src/Y/_outro.js
deleted file mode 100644 (file)
index 22a7560..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-
-})();
similarity index 81%
rename from src/Y/alias.js
rename to src/Y/alias.cjs
index 01249a8..6898c30 100644 (file)
@@ -1,4 +1,5 @@
-var globals   = this
+var undefined
+,   globals   = (function(){ return this; })()
 ,   _Object   = globals.Object
 ,   _Function = globals.Function
 ,   _Array    = globals.Array
@@ -6,7 +7,6 @@ var globals   = this
 ,   _Number   = globals.Number
 
 ,   slice    = _Array.prototype.slice
-,   toString = _Object.prototype.toString
 ,   hasOwn   = _Object.prototype.hasOwnProperty
 ,   getProto = _Object.getPrototypeOf
 ;
similarity index 91%
rename from src/Y/y-class.js
rename to src/Y/class.cjs
index 5c7aea0..9ca59ab 100644 (file)
@@ -1,6 +1,8 @@
 // Inspired by John Resig's "Simple Class Inheritence" -- http://ejohn.org/blog/simple-javascript-inheritance/
 
-var KNOWN_CLASSES = {}
+var Y = require('Y').Y
+,   type = require('Y/type')
+,   KNOWN_CLASSES = type.type.KNOWN_CLASSES
 ,   classToString = function toString(){ return this.className+"()"; }
 ;
 
@@ -12,7 +14,7 @@ function _Class() {
     ,   instance = this;
     
     // Not subclassing
-    if ( cls.caller !== Y.Class.fabricate ) {
+    if ( cls.caller !== Class.fabricate ) {
         if ( instance.init ){
             var result = instance.init.apply(instance, arguments);
             if (result) instance = result;
@@ -111,7 +113,7 @@ function Class(className, Parent, members) {
             prototype[k] = members[k];
     }
     
-    if (prototype.init) NewClass.init = prototype.init;
+    if (prototype.init) NewClass.init = Y(prototype.init);
     
     KNOWN_CLASSES[className] = NewClass;
     
@@ -125,9 +127,6 @@ Class.fn.__class__ = Class;
 Class.className = Class.fn.className = "Class";
 
 
-Y.Class = 
-Y.subclass = Class;
-
 /* Class Methods */
 
 /**
@@ -166,8 +165,7 @@ Class.fn.subclass =
 /**
  * Root-class for all Y-objects.
  */
-function YBase(){}
-YBase = Y.YBase = new Class("YBase", {
+var YBase = new Class("YBase", {
     __y__ : true
 });
 
@@ -178,20 +176,13 @@ YBase = Y.YBase = new Class("YBase", {
 
 function bindName(v, k){
     if ( isFunction(v) )
-        this[k] = Y(this[k]).bind(this);
+        this[k] = Y(v).bind(this);
 }
 // bindName = Y(bindName).curry();
 
-Y.bindAll = bindAll;
 function bindAll(o, names){
     var names = new Y(arguments, 1);
     Y(names.size() ? names.generate(Y.op.get(o)) : o).forEach( bindName, o );
-    
-    // if ( names.size() ){
-    //     names.forEach(binder);
-    // } else
-    //     for (var k in o) binder(k);
-    
     return o;
 }
 
@@ -226,4 +217,13 @@ function mixinNames(o, Donor, names, override, yWrap){
     return o;
 }
 
+exports['Class'] =
+exports['subclass']    = Class;
+exports['instantiate'] = Class.instantiate.bind(Class);
+exports['fabricate']   = Class.fabricate.bind(Class);
+
+exports['YBase']          = YBase;
+exports['bindAll']        = bindAll;
+exports['chainDelegates'] = chainDelegates;
+exports['mixinNames']     = mixinNames;
 
similarity index 75%
rename from src/Y/core.js
rename to src/Y/core.cjs
index 9f70f78..83f1594 100644 (file)
@@ -37,6 +37,7 @@ function map(o, fn){
 
 function forEach(o, fn){
     map(o, fn, cxt);
+    return o;
 }
 
 function filter(o, fn){
@@ -91,12 +92,27 @@ function dattr(o, key, value, def){
 }
 
 function extend( A, B ){
-    return slice.call(arguments,1).reduce(extend._extendall, A);
+    return slice.call(arguments,1).reduce(extendall, A);
+}
+function extendall(A, donor){ return reduce(donor, attrvk, A); }
+function attrvk(o, v, k){ return attr(o, k, v, o[k]); }
+
+function dextend( A, B ){
+    return slice.call(arguments,1).reduce(dextendall, A);
 }
-extend._extendall = function _extendall(A, donor){
-    return reduce(donor, extend._set, A);
-};
-extend._set = function _set(o, v, k){
-    return dattr(o, k, v, o[k]);
-};
+function dextendall(A, donor){ return reduce(donor, dattrvk, A); }
+function dattrvk(o, v, k){ return dattr(o, k, v, o[k]); }
+
+
+exports['reduce']  = reduce;
+exports['map']     = map;
+exports['forEach'] = forEach;
+exports['filter']  = filter;
+
+exports['set']     = set;
+exports['attr']    = attr;
+exports['extend']  = extend;
 
+exports['dset']    = dset;
+exports['dattr']   = dattr;
+exports['dextend'] = dextend;
diff --git a/src/Y/index.cjs b/src/Y/index.cjs
new file mode 100644 (file)
index 0000000..4b3e16b
--- /dev/null
@@ -0,0 +1,71 @@
+
+/// Import our external deps first ///
+require('lessly/future');
+require('functional/to-function');
+
+/// Set up core and utilities ///
+var core = require('Y/core')
+,   type = require('Y/type')
+,   Y    = require('Y/y').Y
+;
+
+exports['Y'] = Y;
+
+// Copy all our type utils onto the type function, as it has the
+// same name as its namespace
+core.extend(type.type, type);
+
+// Attach core & type to Y
+core.extend(Y, core, type);
+
+// Make top-level setters refer to the delegating versions
+Y['core']   = core;
+Y['set']    = core.dset;
+Y['attr']   = core.dattr;
+Y['extend'] = core.dextend;
+
+
+/// Patch modules that weren't available earlier ///
+
+// Attach YFunction methods to library functions
+var yfn = require('Y/types/function')
+,   YFunction = Y['YFunction'] = yfn.YFunction ;
+
+YFunction(Y);
+core.forEach(core, YFunction);
+YFunction(Y.type);
+Y['is'] = YFunction(Y.is).curry();
+
+addNames('curry methodize genericize compose chain memoize', yfn);
+
+// Curry all operators
+var op = require('Y/op');
+core.forEach(op, YFunction);
+Y['op'] = op.extend({}, core.map(yfn.curry, op));
+// Y['op'] = core.reduce(op, function(Yop, fn, k){
+//     Yop[k] = yfn.curry(fn);
+//     return Yop;
+// }, {});
+
+// var yclass = require('Y/types/class');
+addNames('Class subclass instantiate fabricate YBase',
+    require('Y/class'));
+
+
+/// Now start assembling the normal sub-modules ///
+addNames('YCollection',   require('Y/types/collection'));
+addNames('YArray',        require('Y/types/array'));
+addNames('YObject',       require('Y/types/object'));
+addNames('YString',       require('Y/types/string'));
+addNames('YNumber range', require('Y/types/number'));
+
+// var ycollection = require('Y/types/collection')
+// ,   yarray      = require('Y/types/array')
+// ,   yobject     = require('Y/types/object')
+// ,   ystring     = require('Y/types/string')
+// ,   ynumber     = require('Y/types/number')
+// ;
+
+
+function addName(name){ Y[name] = this[name]; }
+function addNames(names, ns){ names.split(' ').forEach(addName, ns); }
similarity index 86%
rename from src/Y/y-op.js
rename to src/Y/op.cjs
index 7d295ea..97ef023 100644 (file)
@@ -1,6 +1,8 @@
-
 /* A subset of the functional operators, used in Y's core */
-Y.op = { 
+
+var Y    = require('Y').Y
+,   core = require('Y/core')
+,   op = { // XXX: Make these function statements?
     
     // comparison
     cmp:    function(x,y){  return x == y ? 0 : (x > y ? 1 : -1); },
@@ -52,8 +54,8 @@ Y.op = {
     has:     function(o,k){     return k in o; },
     get:     function(o,k){     return o[k] },
     getdef:  function(o,k,def){ return (k in o ? o[k] : def); },
-    set:     set,  // set(  o, key, value, def )
-    attr:    attr, // attr( o, key, value, def )
+    set:     core.set,  // set(  o, key, value, def )
+    attr:    core.attr, // attr( o, key, value, def )
     method: function(name){
         var args = Y(arguments,1);
         return function(obj){
@@ -64,15 +66,13 @@ Y.op = {
         };
     },
     extend : function extend(A,B){
-        return slice.call(arguments,1).reduce('A donor -> Y.reduce(donor, Y.op.vkset, A)'.lambda(), A);
+        return slice.call(arguments,1).reduce(extender, A);
     }
     
 };
 
+function extender(target, donor){
+    return core.reduce(donor, op.vkset, target);
+}
 
-// Curry all operators
-Y.op = Y.reduce(Y.op, function(op, fn, k){
-    op[k] = Y( Y(fn).curry() );
-    return op;
-}, {});
-
+core.extend(exports, op);
similarity index 100%
rename from src/Y/to-function.js
rename to src/Y/tofunction.cjs
similarity index 62%
rename from src/Y/type.js
rename to src/Y/type.cjs
index a4be9df..0063683 100644 (file)
@@ -1,14 +1,34 @@
 // Type Utilities //
 // Much borrowed from jQuery
 
+var undefined
+,   globals   = (function(){ return this; })()
+,   _Object   = globals.Object
+,   _Function = globals.Function
+,   _Array    = globals.Array
+,   _String   = globals.String
+,   _Number   = globals.Number
+
+,   FN = "constructor"
+,   PT = "prototype"
+,   OP = _Object[PT]
+
+,   slice    = _Array[PT].slice
+,   getProto = _Object.getPrototypeOf
+,   hasOwn   = OP.hasOwnProperty
+,   toString = OP.toString
+,   hasOwn   = OP.hasOwnProperty
+
+,   KNOWN_CLASSES =