+++ /dev/null
-(function(){
-
-this.Y = Y;
-
-var globals = this
+var undefined
+, globals = (function(){ return this; })()
, _Object = globals.Object
, _Function = globals.Function
, _Array = globals.Array
, _Number = globals.Number
, slice = _Array.prototype.slice
-, toString = _Object.prototype.toString
, hasOwn = _Object.prototype.hasOwnProperty
, getProto = _Object.getPrototypeOf
;
// 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+"()"; }
;
, 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;
prototype[k] = members[k];
}
- if (prototype.init) NewClass.init = prototype.init;
+ if (prototype.init) NewClass.init = Y(prototype.init);
KNOWN_CLASSES[className] = NewClass;
Class.className = Class.fn.className = "Class";
-Y.Class =
-Y.subclass = Class;
-
/* Class Methods */
/**
/**
* Root-class for all Y-objects.
*/
-function YBase(){}
-YBase = Y.YBase = new Class("YBase", {
+var YBase = new Class("YBase", {
__y__ : true
});
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;
}
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;
function forEach(o, fn){
map(o, fn, cxt);
+ return o;
}
function filter(o, fn){
}
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;
--- /dev/null
+
+/// 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); }
-
/* 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); },
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){
};
},
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);
// 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 =