Comparing version 0.0.8 to 0.0.9
@@ -0,1 +1,30 @@ | ||
0.0.9 /2012-02-16 | ||
=== | ||
* Complete redesign of comb.define to be more flexible and efficient | ||
* this._super does not require and Arguments object any more to call super | ||
* added "use strict" to all tests | ||
* New Features | ||
* comb.serial method for executing methods that return promises serially | ||
* comb.wrap method for wrapping node methods that require a function callback, with a promise | ||
* new date helper methods | ||
* comb.yearsFromNow | ||
* comb.yearsAgo | ||
* comb.daysFromNow | ||
* comb.daysAgo | ||
* comb.monthsFromNow | ||
* comb.monthsAgo | ||
* comb.hoursFromNow | ||
* comb.hoursAgo | ||
* comb.minutesFromNow | ||
* comb.minutesAgo | ||
* comb.secondsFromNow | ||
* comb.secondsAgo | ||
* comb.hitchIgnore/bindIngore for binding a method to a certain scope but ignoring all passed in parameters | ||
* comb.number.roundCeil for round numbers up always | ||
* Bug Fixes | ||
* Fixed logging appender level setting, before the appenders level would always be overriden on initialization | ||
0.0.8 / 2012-02-9 | ||
@@ -2,0 +31,0 @@ === |
@@ -1,2 +0,2 @@ | ||
var obj = require("./object"), string = require("./string"), date = require("./date"), number = require("./number"), misc = require("./misc"); | ||
var obj = require("./object"), misc = require("./misc"); | ||
@@ -3,0 +3,0 @@ |
var func = require("./functions"), | ||
obj = require("./object"), | ||
define = require("../define").define; | ||
obj = require("./object"); | ||
@@ -5,0 +4,0 @@ var comb = exports; |
@@ -955,2 +955,151 @@ var string = require("./string").string; | ||
date = comb.date; | ||
date = comb.date; | ||
/** | ||
* Adds the specified year/s to the current date. | ||
* | ||
* @example | ||
* | ||
* //assuming that current year is 2012 | ||
* comb.yearsFromNow(1); //2013-mm-dd hh:MM:ss | ||
* | ||
* @param {Number} val the number of years to add | ||
* | ||
* @return {Date} a date with the number of years added | ||
*/ | ||
comb.yearsFromNow = function (val) { | ||
return date.add(new Date(), "years", val); | ||
}; | ||
/** | ||
* Subtracts the specified year/s from the current date. | ||
* | ||
* @param {Number} val the number of years to subtract | ||
* | ||
* @return {Date} a date with the number of years subtracted | ||
*/ | ||
comb.yearsAgo = function (val) { | ||
return date.add(new Date(), "years", -val); | ||
}; | ||
/** | ||
* Adds the specified month/s to the current date. | ||
* | ||
* @example | ||
* | ||
* //assuming that current month is february | ||
* comb.yearsFromNow(2); //yyyy-04-dd hh:MM:ss | ||
* | ||
* @param {Number} val the number of months to add | ||
* | ||
* @return {Date} a date with the number of years added | ||
*/ | ||
comb.monthsFromNow = function (val) { | ||
return date.add(new Date(), "months", val); | ||
}; | ||
/** | ||
* Subtracts the specified month/s from the current date. | ||
* | ||
* @param {Number} val the number of months to subtract | ||
* | ||
* @return {Date} a date with the number of monts subtracted | ||
*/ | ||
comb.monthsAgo = function (val) { | ||
return date.add(new Date(), "months", -val); | ||
}; | ||
/** | ||
* Adds the specified days/s to the current date. | ||
* | ||
* @param {Number} val the number of days to add | ||
* | ||
* @return {Date} a date with the number of days added | ||
*/ | ||
comb.daysFromNow = function (val) { | ||
return date.add(new Date(), "days", val); | ||
}; | ||
/** | ||
* Subtracts the specified days/s from the current date. | ||
* | ||
* @param {Number} val the number of days to subtract | ||
* | ||
* @return {Date} a date with the number of days subtracted | ||
*/ | ||
comb.daysAgo = function (val) { | ||
return date.add(new Date(), "days", -val); | ||
}; | ||
/** | ||
* Adds the specified hour/s to the current date. | ||
* | ||
* @param {Number} val the number of hours to add | ||
* | ||
* @return {Date} a date with the number of hours added | ||
*/ | ||
comb.hoursFromNow = function (val) { | ||
return date.add(new Date(), "hours", val); | ||
}; | ||
/** | ||
* Subtracts the specified hour/s from the current date. | ||
* | ||
* @param {Number} val the number of hours to subtract | ||
* | ||
* @return {Date} a date with the number of hours subtracted | ||
*/ | ||
comb.hoursAgo = function (val) { | ||
return date.add(new Date(), "hours", -val); | ||
}; | ||
/** | ||
* Adds the specified minutes/s to the current date. | ||
* | ||
* @param {Number} val the number of minutes to add | ||
* | ||
* @return {Date} a date with the number of minutes added | ||
*/ | ||
comb.minutesFromNow = function (val) { | ||
return date.add(new Date(), "minutes", val); | ||
}; | ||
/** | ||
* Subtracts the specified minutes/s from the current date. | ||
* | ||
* @param {Number} val the number of minutes to subtract | ||
* | ||
* @return {Date} a date with the number of minutes subtracted | ||
*/ | ||
comb.minutesAgo = function (val) { | ||
return date.add(new Date(), "minutes", -val); | ||
}; | ||
/** | ||
* Adds the specified second/s to the current date. | ||
* | ||
* @param {Number} val the number of seconds to add | ||
* | ||
* @return {Date} a date with the number of seconds added | ||
*/ | ||
comb.secondsFromNow = function (val) { | ||
return date.add(new Date(), "seconds", val); | ||
}; | ||
/** | ||
* Subtracts the specified seconds/s from the current date. | ||
* | ||
* @param {Number} val the number of seconds to subtract | ||
* | ||
* @return {Date} a date with the number of seconds subtracted | ||
*/ | ||
comb.secondsAgo = function (val) { | ||
return date.add(new Date(), "seconds", -val); | ||
}; |
@@ -1,6 +0,5 @@ | ||
var comb = exports; | ||
/** | ||
* Determins if something is a function | ||
* Determines if something is a function | ||
* @param {Anything} obj the thing to test if it is a function | ||
@@ -10,3 +9,3 @@ * | ||
*/ | ||
comb.isFunction = function(obj) { | ||
comb.isFunction = function (obj) { | ||
return typeof obj == "function"; | ||
@@ -24,3 +23,3 @@ }; | ||
*/ | ||
comb.hitch = function(scope, method, args) { | ||
comb.hitch = function (scope, method, args) { | ||
var args = Array.prototype.slice.call(arguments).slice(2); | ||
@@ -31,3 +30,3 @@ if (typeof method == "string") { | ||
if (method) { | ||
return function() { | ||
return function () { | ||
var scopeArgs = args.concat(Array.prototype.slice.call(arguments)); | ||
@@ -41,3 +40,56 @@ return method.apply(scope, scopeArgs); | ||
/** | ||
* @function | ||
* Binds a method to a particular scope | ||
* | ||
* @param {Object} scope the scope to bind the callback to | ||
* @param {String|Function} method the method to callback | ||
* @param [args] optional args to pass to the callback | ||
* | ||
* @returns {Function} the hitched function | ||
*/ | ||
comb.bind = comb.hitch; | ||
/** | ||
* Binds a method to a particular scope ignoring any new arguments passed | ||
* into the functuion. This useful if you want to force particular arguments and | ||
* ignore any new ones | ||
* | ||
* @param {Object} scope the scope to bind the callback to | ||
* @param {String|Function} method the method to callback | ||
* @param [args] optional args to pass to the callback | ||
* | ||
* @returns {Function} the hitched function | ||
*/ | ||
comb.hitchIgnore = function (scope, method, args) { | ||
var args = Array.prototype.slice.call(arguments).slice(2); | ||
if (typeof method == "string") { | ||
method = scope[method]; | ||
} | ||
if (method) { | ||
return function () { | ||
return method.apply(scope, args); | ||
}; | ||
} else { | ||
throw new Error(method + "Method not defined"); | ||
} | ||
}; | ||
/** | ||
* @function | ||
* Binds a method to a particular scope ignoring any new arguments passed | ||
* into the functuion. This useful if you want to force particular arguments and | ||
* ignore any new ones | ||
* | ||
* @param {Object} scope the scope to bind the callback to | ||
* @param {String|Function} method the method to callback | ||
* @param [args] optional args to pass to the callback | ||
* | ||
* @returns {Function} the hitched function | ||
*/ | ||
comb.bindIgnore = comb.hitchIgnore; | ||
/** | ||
* Allows the passing of additional arguments to a function when it is called | ||
@@ -51,8 +103,8 @@ * especially useful for callbacks that you want to provide additional parameters to | ||
*/ | ||
comb.partial = function(method, args) { | ||
comb.partial = function (method, args) { | ||
var args = Array.prototype.slice.call(arguments).slice(1); | ||
if (typeof method == "function") { | ||
return function() { | ||
return function () { | ||
var scopeArgs = args.concat(Array.prototype.slice.call(arguments)); | ||
return method.apply(null, scopeArgs); | ||
return method.apply(this, scopeArgs); | ||
}; | ||
@@ -64,6 +116,6 @@ } else { | ||
var curry = function(f, execute) { | ||
return function(arg) { | ||
var curry = function (f, execute) { | ||
return function (arg) { | ||
var args = Array.prototype.slice.call(arguments); | ||
return execute ? f.apply(this, arguments) : function(arg) { | ||
return execute ? f.apply(this, arguments) : function (arg) { | ||
return f.apply(this, args.concat(Array.prototype.slice.call(arguments))); | ||
@@ -96,3 +148,3 @@ }; | ||
* */ | ||
comb.curry = function(depth, cb, scope) { | ||
comb.curry = function (depth, cb, scope) { | ||
var f; | ||
@@ -99,0 +151,0 @@ if (scope) { |
@@ -38,3 +38,15 @@ var comb = exports; | ||
/** | ||
* Determins if the obj is not undefined | ||
* | ||
* @param obj the thing to test if it is not undefined | ||
* | ||
* @return {Boolean} true if it is defined false otherwise | ||
*/ | ||
comb.isDefined = function(obj){ | ||
return !comb.isUndefined(obj); | ||
} | ||
/** | ||
* Determines if obj is undefined or null | ||
@@ -41,0 +53,0 @@ * |
@@ -35,3 +35,15 @@ var comb = exports; | ||
return (Math.ceil(factor * +number) / factor).toFixed(places) * 1; // Number | ||
}, | ||
/** | ||
* Rounds a number to the specified places, rounding up. | ||
* | ||
* | ||
* @param {Number} num the number to round. | ||
* @param {Number} places the number of places to round to. | ||
*/ | ||
roundCeil : function(number, places){ | ||
return Math.ceil(number * Math.pow(10, places))/Math.pow(10, places); | ||
} | ||
}; |
@@ -97,3 +97,3 @@ var comb = exports; | ||
* Determins if an object is just a hash and not a qualified Object such as number | ||
* | ||
* | ||
* @example | ||
@@ -100,0 +100,0 @@ * comb.isHash({}) => true |
@@ -208,4 +208,4 @@ var define = require("../define").define, | ||
scope = scope || this; | ||
var construct = this.constructor; | ||
var ret = new construct(); | ||
var construct = this._static; | ||
var ret = new this._static(); | ||
this.traverse(this.__root, order, function(node) { | ||
@@ -232,4 +232,3 @@ ret.insert(cb.call(scope, node, this)); | ||
scope = scope || this; | ||
var construct = this.constructor; | ||
var ret = new construct(); | ||
var ret = new this._static(); | ||
this.traverse(this.__root, order, function(node) { | ||
@@ -236,0 +235,0 @@ var include = cb.call(scope, node, this); |
@@ -1,2 +0,2 @@ | ||
var base = require("./base/object"); | ||
var base = require("./base"), toArray = base.array.toArray, merge = base.merge; | ||
@@ -9,84 +9,48 @@ /** | ||
/** | ||
* Alias to call the super method of a particular class | ||
* | ||
* @ignore | ||
*/ | ||
var callSuper = function (args, a) { | ||
if (!args && !a) { | ||
throw new Error("arguments must be defined."); | ||
} | ||
var f = "", u; | ||
var callee, m, meta = this.__meta || {}, pos, supers, l; | ||
if (!a) { | ||
a = args; | ||
} | ||
if (args.callee) { | ||
callee = args.callee; | ||
!f && (f = callee._name); | ||
u = callee._unique; | ||
pos = meta.pos, supers = meta.supers, l = meta.supers.length; | ||
if (f != "constructor") { | ||
if (meta.unique === u) { | ||
pos = 0; | ||
} else if (callee != meta.callee) { | ||
pos = 0; | ||
for (; pos < l; pos++) { | ||
var sup = supers[pos], sm = sup ? sup[f] : null; | ||
if (sm == callee) { | ||
pos++; | ||
break; | ||
var functionWrapper = function (f, name, supers) { | ||
var wrapper = function () { | ||
var orgSuper = this._super, ret; | ||
if (this.__meta) { | ||
var supers = this.__meta.supers, l = supers.length, pos = 0; | ||
if (l) { | ||
this._super = function (args, a) { | ||
if (a) { | ||
args = a; | ||
} | ||
} | ||
} | ||
for (; pos < l; pos++) { | ||
var sup = supers[pos], sm = sup ? sup[f] : null; | ||
if (sm && sm != callee) { | ||
m = sm; | ||
break; | ||
} | ||
} | ||
} else { | ||
if (meta.unique === u) { | ||
pos = 0; | ||
} else if (callee != meta.callee) { | ||
pos = 0; | ||
for (; pos < l; pos++) { | ||
var sup = supers[pos].__meta.proto; | ||
if (sup.instance && sup.instance.hasOwnProperty(f)) { | ||
sm = sup.instance[f]; | ||
if (sm == callee) { | ||
pos++; | ||
var m; | ||
while (!m && pos < l) { | ||
var sup = supers[pos++], m = sup[name]; | ||
if (m && (m = m._f || m) && "function" === typeof m && m !== f) { | ||
break; | ||
} else { | ||
m = null; | ||
} | ||
} | ||
} | ||
} | ||
for (; pos < l; pos++) { | ||
var sup = supers[pos].__meta.proto; | ||
if (sup.instance && sup.instance.hasOwnProperty(f)) { | ||
sm = sup.instance[f]; | ||
if (sm && sm != callee) { | ||
m = sm; | ||
break; | ||
if (m) { | ||
return m.apply(this, args); | ||
} else { | ||
return null; | ||
} | ||
} | ||
}; | ||
} else { | ||
this._super = function () { | ||
return null; | ||
}; | ||
} | ||
ret = f.apply(this, arguments); | ||
this._super = orgSuper || null; | ||
} else { | ||
ret = f.apply(this, arguments); | ||
} | ||
} else { | ||
throw new Error("can't find the _super"); | ||
return ret; | ||
} | ||
meta.callee = m; | ||
meta.pos = m ? ++pos : -1; | ||
if (m) { | ||
return m.apply(this, a); | ||
} else { | ||
return null; | ||
} | ||
wrapper._f = f; | ||
return wrapper; | ||
}; | ||
/** | ||
* @ignore | ||
*/ | ||
var defineMixinProps = function (child, proto, unique) { | ||
var defineMixinProps = function (child, proto) { | ||
if (proto) { | ||
@@ -111,6 +75,11 @@ var operations = proto.setters; | ||
if (proto) { | ||
for (j in proto) { | ||
for (var j in proto) { | ||
if (j != "getters" && j != "setters") { | ||
if (!child.hasOwnProperty(j)) { | ||
child[j] = proto[j]; | ||
var p = proto[j]; | ||
if ("function" === typeof p) { | ||
if (!child.hasOwnProperty(j)) { | ||
child[j] = functionWrapper(defaultFunction, j); | ||
} | ||
} else { | ||
child[j] = p; | ||
} | ||
@@ -131,5 +100,4 @@ } | ||
var m = args[i]; | ||
var proto = m.prototype.__meta.proto; | ||
defineMixinProps(child, proto.instance, constructor._unique); | ||
defineMixinProps(this, proto.static, constructor._unique); | ||
defineMixinProps(child, m.prototype.__meta.proto, constructor._unique); | ||
defineMixinProps(this, m.__meta.proto, constructor._unique); | ||
//copy the bases for static, | ||
@@ -151,5 +119,5 @@ var staticSupers = this.__meta.supers, supers = child.__meta.supers; | ||
if (bases.indexOf(unique) == -1) { | ||
arr.push(sup); | ||
//add their id to our bases | ||
bases.push(unique); | ||
arr.push(sup); | ||
var supers = sup.__meta.supers, l = supers.length; | ||
@@ -183,10 +151,14 @@ if (supers && l) { | ||
} | ||
var constructorFound = false; | ||
for (i in proto) { | ||
if (i != "getters" && i != "setters") { | ||
var f = proto[i]; | ||
if (typeof f == "function") { | ||
f._name = i; | ||
f._unique = "define" + classCounter; | ||
} | ||
if (i != "constructor") { | ||
if ("function" === typeof f) { | ||
var meta = f.__meta || {}; | ||
if (!meta.isConstructor) { | ||
child[i] = functionWrapper(f, i); | ||
}else{ | ||
child[i] = f; | ||
} | ||
} else { | ||
child[i] = f; | ||
@@ -199,2 +171,6 @@ } | ||
var defaultFunction = function () { | ||
return this._super(arguments); | ||
}; | ||
var _export = function (obj, name) { | ||
@@ -216,49 +192,39 @@ if (obj && name) { | ||
var childProto = child.prototype, supers = []; | ||
if (sup instanceof Array) { | ||
supers = sup; | ||
if (sup) { | ||
supers = toArray(sup); | ||
sup = supers.shift(); | ||
} else { | ||
supers = []; | ||
} | ||
var bases = [], meta, staticMeta; | ||
var unique = "define" + classCounter, bases = [], staticBases = []; | ||
var instanceSupers = [], staticSupers = []; | ||
if (sup) { | ||
child.__proto__ = sup; | ||
childProto.__proto__ = sup.prototype; | ||
meta = childProto.__meta = { | ||
supers:mixinSupers(sup.prototype, bases), | ||
superPos:0, | ||
superName:"", | ||
unique:"define" + classCounter | ||
}; | ||
staticMeta = child.__meta = { | ||
supers:mixinSupers(sup, []), | ||
superPos:0, | ||
superName:"", | ||
unique:"define" + classCounter | ||
}; | ||
} else { | ||
meta = childProto.__meta = { | ||
supers:[], | ||
superPos:0, | ||
superName:"", | ||
unique:"define" + classCounter | ||
}; | ||
staticMeta = child.__meta = { | ||
supers:[], | ||
superPos:0, | ||
superName:"", | ||
unique:"define" + classCounter | ||
}; | ||
instanceSupers = mixinSupers(sup.prototype, bases), staticSupers = mixinSupers(sup, staticBases); | ||
} | ||
meta.proto = proto; | ||
var meta = childProto.__meta = { | ||
supers:instanceSupers, | ||
superName:"", | ||
unique:unique, | ||
bases:bases | ||
}; | ||
var childMeta = child.__meta = { | ||
supers:staticSupers, | ||
superName:"", | ||
unique:unique, | ||
bases:staticBases, | ||
isConstructor:true | ||
}; | ||
childProto._static = child; | ||
defineProps(childProto, proto.instance); | ||
defineProps(child, proto.static); | ||
meta.bases = bases; | ||
staticMeta.bases = bases; | ||
var instance = meta.proto = merge({constructor:defaultFunction}, proto.instance || {}); | ||
var stat = childMeta.proto = merge({init:defaultFunction}, proto.static || {}); | ||
defineProps(childProto, instance, false); | ||
defineProps(child, stat, true); | ||
if (supers.length) { | ||
mixin.apply(child, supers.reverse()); | ||
mixin.apply(child, supers); | ||
} | ||
child.mixin = mixin; | ||
child.as = _export; | ||
child._super = callSuper; | ||
childProto._super = callSuper; | ||
classCounter++; | ||
@@ -269,3 +235,3 @@ return child; | ||
base.merge(exports, { | ||
merge(exports, { | ||
/**@lends comb*/ | ||
@@ -501,19 +467,5 @@ | ||
define:function (sup, proto) { | ||
proto = proto || {}; | ||
var child = function () { | ||
//if a unique wasn't defined then the | ||
//child didn't define one! | ||
var instance = this.__meta.proto.instance; | ||
if (instance && instance.constructor && instance.constructor._unique) { | ||
instance.constructor.apply(this, arguments); | ||
} else { | ||
var supers = this.__meta.supers, l = supers.length; | ||
for (var i = 0; i < l; i++) { | ||
var protoInstance = supers[i].__meta.proto.instance; | ||
if (protoInstance && protoInstance.hasOwnProperty("constructor")) { | ||
protoInstance.constructor.apply(this, arguments); | ||
break; | ||
} | ||
} | ||
} | ||
this.constructor.apply(this, arguments); | ||
}; | ||
@@ -541,19 +493,6 @@ var ret = __define(child, sup, proto); | ||
var retInstance; | ||
proto = proto || {}; | ||
var child = function () { | ||
if (!retInstance) { | ||
//if a unique wasn't defined then the | ||
//child didn't define one! | ||
var instance = this.__meta.proto.instance; | ||
if (instance && instance.constructor._unique) { | ||
instance.constructor.apply(this, arguments); | ||
} else { | ||
var supers = this.__meta.supers, l = supers.length; | ||
for (var i = 0; i < l; i++) { | ||
var protoInstance = supers[i].__meta.proto.instance; | ||
if (protoInstance && protoInstance.hasOwnProperty("constructor")) { | ||
protoInstance.constructor.apply(this, arguments); | ||
break; | ||
} | ||
} | ||
} | ||
this.constructor.apply(this, arguments); | ||
retInstance = this; | ||
@@ -560,0 +499,0 @@ } |
@@ -41,4 +41,2 @@ var define = require("../../define.js").define, base = require("../../base"), Level = require("../level"); | ||
this.__level = level; | ||
}else{ | ||
this.__level = Level.INFO; | ||
} | ||
@@ -62,3 +60,3 @@ }, | ||
_canAppend : function(event) { | ||
return event.level.isGreaterOrEqualToo(this.__level); | ||
return !base.isUndefinedOrNull(this.__level) && event.level.isGreaterOrEqualToo(this.__level); | ||
}, | ||
@@ -65,0 +63,0 @@ |
@@ -58,3 +58,3 @@ var define = require("../../define.js").define, | ||
this.__writeStream = options.writeStream || fs.createWriteStream(this.__file, { flags: this.__overwrite ? "w" : 'a', encoding: this.__encoding}); | ||
this._super(arguments, [options]); | ||
this._super([options]); | ||
this.__pattern += "\n"; | ||
@@ -61,0 +61,0 @@ process.addListener("exit", base.hitch(this, "__onExit")); |
@@ -63,3 +63,3 @@ var define = require("../../define.js").define, | ||
this.__writeStream.write("[\n"); | ||
this.__level = options.level; | ||
this.level = options.level; | ||
//explicit overwrite of patter | ||
@@ -66,0 +66,0 @@ this.__pattern = '{"timestamp" : "{timeStamp}", "level" : "{levelName}", "name" : "{name}", "message" : "{message}"}'; |
var define = require("../define.js"), | ||
base = require("../base"), | ||
Level = require("./level"), | ||
appenders = require("./appenders"), | ||
configurators = require("./config"); | ||
base = require("../base"), | ||
Level = require("./level"), | ||
appenders = require("./appenders"), | ||
configurators = require("./config"); | ||
var rootTree; | ||
var LoggerTree = define.define(null, { | ||
instance : { | ||
instance:{ | ||
constructor : function(root) { | ||
constructor:function (root) { | ||
this.__root = root; | ||
@@ -18,3 +18,3 @@ this.__name = root.name; | ||
__getSubLoggers : function() { | ||
__getSubLoggers:function () { | ||
var map = this.__map, ret = [], n; | ||
@@ -30,15 +30,15 @@ for (var i in map) { | ||
__getLoggers : function() { | ||
__getLoggers:function () { | ||
return [this.__root].concat(this.__getSubLoggers()) | ||
}, | ||
getCurrentLoggers : function() { | ||
getCurrentLoggers:function () { | ||
return this.__getLoggers(); | ||
}, | ||
getSubLoggers : function() { | ||
getSubLoggers:function () { | ||
return this.__getSubLoggers(); | ||
}, | ||
getLogger : function(name) { | ||
getLogger:function (name) { | ||
var ret; | ||
@@ -67,10 +67,10 @@ if (name) { | ||
getRootLogger : function() { | ||
getRootLogger:function () { | ||
return this.__root; | ||
}, | ||
isDisabled : function(level) { | ||
isDisabled:function (level) { | ||
}, | ||
resetConfiguration : function() { | ||
resetConfiguration:function () { | ||
}, | ||
@@ -82,3 +82,3 @@ | ||
addAppender : function(appender) { | ||
addAppender:function (appender) { | ||
var map = this.__map; | ||
@@ -90,3 +90,3 @@ for (var i in map) { | ||
removeAppender : function(name) { | ||
removeAppender:function (name) { | ||
var map = this.__map; | ||
@@ -98,4 +98,4 @@ for (var i in map) { | ||
setters : { | ||
level : function(level) { | ||
setters:{ | ||
level:function (level) { | ||
this.__level = level; | ||
@@ -113,5 +113,5 @@ if (level && level instanceof Level) { | ||
getters : { | ||
categories : function() { | ||
return this.getCurrentLoggers().map(function(l) { | ||
getters:{ | ||
categories:function () { | ||
return this.getCurrentLoggers().map(function (l) { | ||
return l.fullName; | ||
@@ -121,3 +121,3 @@ }); | ||
name : function() { | ||
name:function () { | ||
var ret = this.__name; | ||
@@ -133,7 +133,7 @@ if (this.__parent) { | ||
level : function() { | ||
level:function () { | ||
return this.__level; | ||
}, | ||
additive : function() { | ||
additive:function () { | ||
return this.__root.additive; | ||
@@ -148,3 +148,3 @@ } | ||
comb.logging = base.merge({ | ||
Level : Level | ||
Level:Level | ||
}, configurators); | ||
@@ -239,6 +239,6 @@ /**@namespace appenders for logging*/ | ||
instance: { | ||
instance:{ | ||
/**@lends comb.logging.Logger.prototype*/ | ||
constructor : function(name, parent) { | ||
constructor:function (name, parent) { | ||
this.__additive = true; | ||
@@ -262,3 +262,3 @@ this.__name = name; | ||
*/ | ||
info : function(message) { | ||
info:function (message) { | ||
this.log(Level.INFO, message); | ||
@@ -272,3 +272,3 @@ }, | ||
*/ | ||
debug : function(message) { | ||
debug:function (message) { | ||
this.log(Level.DEBUG, message); | ||
@@ -282,3 +282,3 @@ }, | ||
*/ | ||
error : function(message) { | ||
error:function (message) { | ||
this.log(Level.ERROR, message); | ||
@@ -292,3 +292,3 @@ }, | ||
*/ | ||
warn : function(message) { | ||
warn:function (message) { | ||
this.log(Level.WARN, message); | ||
@@ -302,3 +302,3 @@ }, | ||
*/ | ||
trace : function(message) { | ||
trace:function (message) { | ||
this.log(Level.TRACE, message); | ||
@@ -312,3 +312,3 @@ }, | ||
*/ | ||
fatal : function(message) { | ||
fatal:function (message) { | ||
this.log(Level.FATAL, message); | ||
@@ -323,3 +323,3 @@ }, | ||
*/ | ||
log : function(level, message) { | ||
log:function (level, message) { | ||
if (level.isGreaterOrEqualToo(this.level)) { | ||
@@ -337,7 +337,7 @@ if (Level.TRACE.equals(level)) { | ||
var event = { | ||
level : level, | ||
levelName : level.name, | ||
message : message, | ||
timeStamp : new Date(), | ||
name : this.fullName | ||
level:level, | ||
levelName:level.name, | ||
message:message, | ||
timeStamp:new Date(), | ||
name:this.fullName | ||
}; | ||
@@ -354,3 +354,3 @@ for (var i in appenders) { | ||
*/ | ||
addAppender : function(appender) { | ||
addAppender:function (appender) { | ||
if (!base.isUndefinedOrNull(appender)) { | ||
@@ -360,3 +360,5 @@ var name = appender.name; | ||
this.__appenders[name] = appender; | ||
appender.level = this.level; | ||
if (!appender.level) { | ||
appender.level = this.level; | ||
} | ||
this._tree.addAppender(appender); | ||
@@ -371,3 +373,3 @@ } | ||
*/ | ||
addAppenders : function(appenders) { | ||
addAppenders:function (appenders) { | ||
appenders.forEach(base.hitch(this, "addAppender")); | ||
@@ -380,3 +382,3 @@ }, | ||
*/ | ||
removeAppender : function(name) { | ||
removeAppender:function (name) { | ||
if (name in this.__appenders) { | ||
@@ -393,3 +395,3 @@ delete this.__appenders[name]; | ||
*/ | ||
removeAppenders : function(appenders) { | ||
removeAppenders:function (appenders) { | ||
appenders.forEach(this.removeAppender, this); | ||
@@ -401,3 +403,3 @@ }, | ||
*/ | ||
removeAllAppenders : function() { | ||
removeAllAppenders:function () { | ||
for (var i in this.__appenders) { | ||
@@ -413,3 +415,3 @@ this.removeAppender(i); | ||
*/ | ||
isAppenderAttached : function(name) { | ||
isAppenderAttached:function (name) { | ||
return (name in this.__appenders); | ||
@@ -426,3 +428,3 @@ }, | ||
*/ | ||
getAppender : function(name) { | ||
getAppender:function (name) { | ||
var ret; | ||
@@ -438,5 +440,5 @@ if (name in this.__appenders) { | ||
* */ | ||
setters : { | ||
setters:{ | ||
level : function(level) { | ||
level:function (level) { | ||
level = Level.toLevel(level); | ||
@@ -455,3 +457,3 @@ if (this.__additive) { | ||
additive : function(additive) { | ||
additive:function (additive) { | ||
this.__additive = additive; | ||
@@ -462,7 +464,7 @@ } | ||
/**@ignore*/ | ||
getters : { | ||
getters:{ | ||
/**@ignore*/ | ||
/**@ignore*/ | ||
subLoggers : function() { | ||
subLoggers:function () { | ||
return this._tree.getSubLoggers(); | ||
@@ -472,3 +474,3 @@ }, | ||
/**@ignore*/ | ||
level : function() { | ||
level:function () { | ||
return this.__level; | ||
@@ -478,7 +480,7 @@ }, | ||
/**@ignore*/ | ||
additive : function() { | ||
additive:function () { | ||
return this.__additive; | ||
}, | ||
isAll : function() { | ||
isAll:function () { | ||
return Level.ALL.isGreaterOrEqualToo(this.level); | ||
@@ -488,3 +490,3 @@ }, | ||
/**@ignore*/ | ||
isDebug : function() { | ||
isDebug:function () { | ||
return Level.DEBUG.isGreaterOrEqualToo(this.level); | ||
@@ -494,3 +496,3 @@ }, | ||
/**@ignore*/ | ||
isTrace : function() { | ||
isTrace:function () { | ||
return Level.TRACE.isGreaterOrEqualToo(this.level); | ||
@@ -500,3 +502,3 @@ }, | ||
/**@ignore*/ | ||
isInfo : function() { | ||
isInfo:function () { | ||
return Level.INFO.isGreaterOrEqualToo(this.level); | ||
@@ -506,3 +508,3 @@ }, | ||
/**@ignore*/ | ||
isWarn : function() { | ||
isWarn:function () { | ||
return Level.WARN.isGreaterOrEqualToo(this.level); | ||
@@ -512,3 +514,3 @@ }, | ||
/**@ignore*/ | ||
isError : function() { | ||
isError:function () { | ||
return Level.ERROR.isGreaterOrEqualToo(this.level); | ||
@@ -518,3 +520,3 @@ }, | ||
/**@ignore*/ | ||
isFatal : function() { | ||
isFatal:function () { | ||
return Level.FATAL.isGreaterOrEqualToo(this.level); | ||
@@ -524,3 +526,3 @@ }, | ||
/**@ignore*/ | ||
isOff : function() { | ||
isOff:function () { | ||
return Level.OFF.equals(this.level); | ||
@@ -530,3 +532,3 @@ }, | ||
/**@ignore*/ | ||
name : function() { | ||
name:function () { | ||
return this.__name; | ||
@@ -536,3 +538,3 @@ }, | ||
/**@ignore*/ | ||
tree : function() { | ||
tree:function () { | ||
return this._tree; | ||
@@ -542,3 +544,3 @@ }, | ||
/**@ignore*/ | ||
appenders : function() { | ||
appenders:function () { | ||
var ret = []; | ||
@@ -551,3 +553,3 @@ for (var i in this.__appenders) { | ||
categories: function() { | ||
categories:function () { | ||
return this._tree.categories; | ||
@@ -558,3 +560,3 @@ } | ||
static : { | ||
static:{ | ||
/**@lends comb.logging.Logger*/ | ||
@@ -565,3 +567,3 @@ | ||
*/ | ||
getRootLogger : function() { | ||
getRootLogger:function () { | ||
return rootTree.getRootLogger(); | ||
@@ -575,3 +577,3 @@ }, | ||
*/ | ||
getLogger : function(name) { | ||
getLogger:function (name) { | ||
return rootTree.getLogger(name); | ||
@@ -578,0 +580,0 @@ } |
@@ -63,8 +63,17 @@ var define = require("../define").define, base = require("../base"); | ||
var ret = this; | ||
Orig.apply(ret, arguments), inSet = false, inGet = false; | ||
Orig.apply(ret, arguments); | ||
var inSet = false, inGet = false; | ||
var prox = base.handlerProxy(ret, { | ||
get:function (receiver, name) { | ||
if (!inSet) { | ||
if (!inSet && !inGet) { | ||
inGet = true; | ||
var retVal = ret[name] || ret.getMissingProperty.apply(prox, [name]); | ||
var retVal; | ||
if(!base.isUndefined(ret[name])){ | ||
retVal = ret[name]; | ||
if(base.isFunction(retVal)){ | ||
retVal = base.hitch(prox, retVal); | ||
} | ||
}else{ | ||
retVal = ret.getMissingProperty.apply(prox, [name]); | ||
} | ||
inGet = false; | ||
@@ -79,3 +88,8 @@ return retVal; | ||
inSet = true; | ||
var retVal = ret[name] || ret.setMissingProperty.apply(prox, [name, val]); | ||
var retVal = ret[name]; | ||
if(base.isUndefined(retVal)){ | ||
retVal = ret.setMissingProperty.apply(prox, [name, val]); | ||
}else{ | ||
retVal = (ret[name] = val); | ||
} | ||
inSet = false; | ||
@@ -82,0 +96,0 @@ }else{ |
@@ -37,9 +37,9 @@ var hitch = require("./base/functions").hitch, | ||
* myFunc.addCallback(do something...) | ||
* myFunc.cain(myfunc).then(do something...) | ||
* myFunc.cain(myfunc).addCallback(do something...) | ||
* myFunc.chain(myfunc).then(do something...) | ||
* myFunc.chain(myfunc).addCallback(do something...) | ||
* | ||
* myFunc2.then(do something...) | ||
* myFunc2.addCallback(do something...) | ||
* myFunc2.cain(myfunc).then(do something...) | ||
* myFunc2.cain(myfunc).addCallback(do something...) | ||
* myFunc2.chain(myfunc).then(do something...) | ||
* myFunc2.chain(myfunc).addCallback(do something...) | ||
* @memberOf comb | ||
@@ -67,5 +67,10 @@ * @constructs | ||
__callNextTick : function(cb, results){ | ||
process.nextTick(hitch(this, function(){ | ||
cb.apply(this, results); | ||
__callNextTick:function (cb, results) { | ||
process.nextTick(hitch(this, function () { | ||
try { | ||
cb.apply(this, results); | ||
} catch (e) { | ||
console.error(e); | ||
throw e; | ||
} | ||
})); | ||
@@ -240,3 +245,2 @@ }, | ||
constructor:function (defs, normalizeResults) { | ||
this.__defLength = defs.length; | ||
this.__errors = []; | ||
@@ -246,3 +250,8 @@ this.__results = []; | ||
this._super(arguments); | ||
defs.forEach(this.__addPromise, this); | ||
if (defs && defs.length) { | ||
this.__defLength = defs.length; | ||
defs.forEach(this.__addPromise, this); | ||
} else { | ||
this.__resolve(); | ||
} | ||
}, | ||
@@ -285,5 +294,10 @@ | ||
__callNextTick : function(cb, results){ | ||
process.nextTick(hitch(this, function(){ | ||
cb.apply(this, [results]); | ||
__callNextTick:function (cb, results) { | ||
process.nextTick(hitch(this, function () { | ||
try { | ||
cb.apply(this, [results]); | ||
} catch (e) { | ||
console.error(e); | ||
throw e; | ||
} | ||
})); | ||
@@ -442,3 +456,4 @@ }, | ||
if (i < l) { | ||
var curr = stack[i], obj = getValueFromArrayMap(curr[0], pMap, handles), m = curr[1], name = m[0], args = m[1], subStack = curr[2], handle = curr[3]; | ||
var curr = stack[i], obj = getValueFromArrayMap(curr[0], pMap, | ||
handles), m = curr[1], name = m[0], args = m[1], subStack = curr[2], handle = curr[3]; | ||
var p; | ||
@@ -600,3 +615,4 @@ try { | ||
isPromiseLike:function (obj) { | ||
return !base.isUndefinedOrNull(obj) && (base.isInstanceOf(obj, Promise) || (base.isFunction(obj.then) && base.isFunction(obj.addCallback) && base.isFunction(obj.addErrback))); | ||
return !base.isUndefinedOrNull(obj) && (base.isInstanceOf(obj, Promise) || (base.isFunction(obj.then) | ||
&& base.isFunction(obj.addCallback) && base.isFunction(obj.addErrback))); | ||
}, | ||
@@ -631,3 +647,3 @@ | ||
} else { | ||
var p = new PromiseList(args.map(function(a){ | ||
var p = new PromiseList(args.map(function (a) { | ||
return exports.isPromiseLike(a) ? a : new Promise().callback(a); | ||
@@ -644,4 +660,113 @@ }), true); | ||
}, | ||
/** | ||
* Wraps traditional node style functions with a promise. | ||
* @example | ||
* | ||
* var fs = require("fs"); | ||
* var readFile = comb.wrap(fs.readFile, fs); | ||
* readFile(__dirname + "/test.json").then( | ||
* function(buffer){ | ||
* console.log(contents); | ||
* }, | ||
* funciton(err){ | ||
* | ||
* } console.error(err); | ||
* ); | ||
* | ||
* | ||
* @param {Function} fn function to wrap | ||
* @param {Object} scope scope to call the function in | ||
* | ||
* @return {Funciton} a wrapped function | ||
*/ | ||
wrap:function (fn, scope) { | ||
return function () { | ||
var ret = new Promise(); | ||
var args = base.argsToArray(arguments); | ||
args.push(function (err, res) { | ||
var args = base.argsToArray(arguments); | ||
if (err) { | ||
ret.errback(err); | ||
} else { | ||
args.shift(); | ||
ret.callback.apply(ret, args); | ||
} | ||
}); | ||
fn.apply(scope || this, args); | ||
return ret; | ||
} | ||
}, | ||
/** | ||
* Executes a list of items in a serial manner. If the list contains promises then each promise | ||
* will be executed in a serial manner, if the list contains non async items then the next item in the list | ||
* is called. | ||
* | ||
* @example | ||
* | ||
* var asyncAction = function(item, timeout){ | ||
* var ret = new comb.Promise(); | ||
* setTimeout(comb.hitchIgnore(ret, "callback", item), timeout); | ||
* return ret; | ||
* }; | ||
* | ||
* comb.serial([ | ||
* comb.partial(asyncAction, 1, 1000), | ||
* comb.partial(asyncAction, 2, 900), | ||
* comb.partial(asyncAction, 3, 800), | ||
* comb.partial(asyncAction, 4, 700), | ||
* comb.partial(asyncAction, 5, 600), | ||
* comb.partial(asyncAction, 6, 500) | ||
* ]).then(function(results){ | ||
* console.log(results); // [1,2,3,4,5,6]; | ||
* }); | ||
* | ||
* | ||
* | ||
* @param list | ||
* @param callback | ||
* @param errback | ||
*/ | ||
serial:function (list, callback, errback) { | ||
var ret = new Promise(), results = [], isErrored = false; | ||
if (base.isArray(list)) { | ||
(function next(index) { | ||
if (index < list.length) { | ||
var item = list[index]; | ||
try { | ||
exports.when(base.isFunction(item) ? item() : item, | ||
function () { | ||
//store results | ||
var args = base.argsToArray(arguments); | ||
results.push(args.length == 1 ? args[0] : args); | ||
process.nextTick(base.partial(next, index + 1)); | ||
}, | ||
function (err) { | ||
//errback | ||
if (!isErrored) { | ||
isErrored = true; | ||
ret.errback.apply(ret, arguments); | ||
} | ||
}); | ||
} catch (e) { | ||
if (!isErrored) { | ||
isErrored = true; | ||
ret.errback(e); | ||
} | ||
} | ||
} else { | ||
ret.callback(results); | ||
} | ||
})(0); | ||
} else { | ||
throw new Error("When calling comb.serial the first argument must be an array"); | ||
} | ||
ret.then(callback, errback); | ||
return ret; | ||
} | ||
}); | ||
{ | ||
"name": "comb", | ||
"description": "A framework for node", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"keywords" : ["OO", "Object Oriented", "Collections", "Tree", "HashTable", "Pool", "Logging", "Promise", "Promises", "Proxy"], | ||
@@ -6,0 +6,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
360894
8709