Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clazz-js

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clazz-js - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

docs/1_Installation.md

2

bower.json
{
"name": "ClazzJS",
"version": "0.3.0",
"version": "0.3.1",
"ignore": [

@@ -5,0 +5,0 @@ "node_modules",

@@ -1,2 +0,2 @@

!function(a,b,c,d){if("function"==typeof define&&define.amd)define(b,c,d);else if("object"==typeof exports&&exports){for(var e=0,f=c.length;f>e;++e){var g=c[e];"string"==typeof g&&(g=g.replace(/([A-Z]+)/g,function(a){return"-"+a.toLowerCase()}).replace(/^-/,""),c[e]=require(g))}var h=d.apply(a,c);for(var i in h)exports[i]=h[i]}else{for(var e=0,f=c.length;f>e;++e){var g=c[e];if("string"==typeof g){if(!(g in a))throw new Error('"'+b+'" dependent on non exited module "'+g+'"!');c[e]=a[g]}}a[b]=d.apply(a,c)}}(new Function("return this")(),"ClazzJS",[],function(a){var b=function(){var a=function(b,c){var d=function(a){var b=d.getScope().getNamespace(d.adjustPath(a));return arguments.length>1&&b.space.apply(b,_.toArray(arguments).slice(1)),b};return _.extend(d,a.prototype),d._scope=b,d._path=c,d._spaces=[],d._objects={},d};_.extend(a.prototype,{getPath:function(){return this._path},getScope:function(){return this._scope},adjustPath:function(a){return this._scope.isAbsolutePath(a)?this._scope.adjustPath(a):this._scope.concatPaths(this.getPath(),a)},get:function(a){return a in this._objects||(this._objects[a]=this._scope.get(a).call(this)),this._objects[a]},has:function(a){return this._scope.has(a)},space:function(){var a=this,b=_.toArray(arguments).slice(0,-1),c=_.last(arguments),d=[];b.length||(b=this._scope.getDefaultInjects());for(var e=0,f=b.length;f>e;++e)d[e]=this.get(b[e]);return this._spaces.push(function(){c.apply(a,d)}),this},executeSpace:function(){return this._spaces.length?(this._spaces.pop()(),!0):!1}});var b=function(a){a=a||{},this._innerDelimiter=a.innerDelimiter||"/",this._delimiters=a.delimiters||["\\","/","."],this._defaultInjects=a.defaultInjects||[],this._namespaces={},this._factories={},this._search=[]};return _.extend(b.prototype,{getInnerDelimiter:function(){return this._innerDelimiter},setInnerDelimiter:function(a){if(!this.hasDelimiter(a))throw new Error('Delimiter "'+a+'" does not supported!');return this._innerDelimiter=a,this},getDelimiters:function(){return this._delimiters},addDelimiter:function(a){if(this.hasDelimiter(a))throw new Error('Delimiter "'+a+'" is already exists!');return this},removeDelimiter:function(a){if(!this.hasDelimiter(a))throw new Error('Delimiter "'+a+'" does not exists!')},hasDelimiter:function(a){return-1!==this._delimiters.indexOf(a)},getNamespace:function(b){return b=this.adjustPath(b),b in this._namespaces||(this._namespaces[b]=a(this,b)),this._namespaces[b]},getRootNamespace:function(){return this.getNamespace(this.getRootPath())},getRootPath:function(){return this._innerDelimiter},adjustPath:function(a){var b=this.getInnerDelimiter(),c=this.getDelimiters();return a.replace(new RegExp("[\\"+c.join("\\")+"]","g"),b).replace(new RegExp(b+"+","g"),b).replace(new RegExp("(.+)"+b+"$"),function(a){return a})},isAbsolutePath:function(a){return 0===a.indexOf(this.getRootNamespace().getPath())},concatPaths:function(){return this.adjustPath(_.toArray(arguments).join(this.getInnerDelimiter()))},set:function(a,b){if(a in this._factories)throw new Error('Factory for object "'+a+'" is already exists!');return this._factories[a]=b,this},get:function(a){if(!(a in this._factories))throw new Error('Factory for object "'+a+'" does not exists!');return this._factories[a]},has:function(a){return a in this._factories},remove:function(a){return delete this._factories[a],this},getInSearchError:function(a){var b=new Error('Path "'+a+'" is in search state!');return b.inSearch=!0,b.path=a,b},isInSearchError:function(a){return a.inSearch},search:function(a,b){a=this.adjustPath(a);var c=b(a);if(!_.isUndefined(c))return c;for(var d=this.getInnerDelimiter(),e=a.split(d),f=e.pop();e.length;){var g=e.join(d);if(g in this._namespaces)for(var h=this._namespaces[g];h.executeSpace();)if(c=b(g+d+f),!_.isUndefined(c))return c;f=e.pop()}},getDefaultInjects:function(){return this._defaultInjects},addDefaultInject:function(a){if(-1!==this._defaultInjects.indexOf(a))throw new Error('Default inject "'+a+'" is already exists!');return this._defaultInjects.push(a),this},removeDefaultInject:function(a){var b=this._defaultInjects.indexOf(a);if(-1===b)throw new Error('Default inject "'+a+'" does not exists!');return this._defaultInjects.splice(b,1),this}}),{Namespace:a,Scope:b}}(),c=function(){var a=function(){this._processors={}};_.extend(a.prototype,{getProcessor:function(a){return this.checkProcessor(a),this._processors[a]},hasProcessor:function(a){return a in this._processors},setProcessor:function(a,b){return _.isFunction(b)&&(b={process:b}),"__name"in b||(b.__name=a),this._processors[a]=b,this},removeProcessor:function(a){this.checkProcessor(a);var b=this._processors[a];return delete this._processors[a],b},getProcessors:function(){return this._processors},setProcessors:function(a){for(var b in a)this.setProcessor(b,a[b]);return this},checkProcessor:function(a){if(!this.hasProcessor(a))throw new Error('Meta processor "'+a+'" does not exists!')}});var b=function(a,c){var d=function(a,b){return _.isUndefined(b)?d.get(a):d.set(a,b)};return _.extend(d,b.prototype),d._manager=a,d._namespace=c,d};return _.extend(b.prototype,{getManager:function(){return this._manager},getNamespace:function(){return this._namespace},get:function(a){var b=this.getManager(),c=this.resolveProcessorName(a);if(!c)throw new Error('Meta processor "'+a+'" does not exist!');return b.getProcessor(c)},set:function(a,b){var c=this.getNamespace(),d=this.getManager();return d.setProcessor(c.adjustPath(a),b),this},resolveProcessorName:function(a){var b=this.getManager(),c=this.getNamespace();return c.getScope().search(c.adjustPath(a),function(a){return b.hasProcessor(a)?a:void 0})}}),{Meta:b,Manager:a}}(),d=function(){var b=function(a,c,d){var e=function(a,b,c){var d=_.last(arguments);return _.isFunction(d)||"[object Object]"===Object.prototype.toString.call(d)?(e.set(a,b,c),void 0):e.get(a,b)};return _.extend(e,b.prototype),e._manager=a,e._factory=c,e._namespace=d,e};_.extend(b.prototype,{getManager:function(){return this._manager},getFactory:function(){return this._factory},getNamespace:function(){return this._namespace},has:function(a){return!!this.resolveName(a)},get:function(a,b){var c=this.resolvePath(a);if(!c)throw new Error('Clazz "'+a+'" does not exists!');b=b||[];var d=this.getManager();if(!d.hasClazz(c,b)){var e=this.getFactory(),f=d.getClazzData(c);d.setClazz(c,e.create({name:f.name,parent:f.parent,meta:f.meta,dependencies:b}),b)}return d.getClazz(c,b)},set:function(a,b,c){var d=this.getNamespace(),e=this.getManager();return _.isUndefined(c)&&(c=b,b=null),a=d.adjustPath(a),e.setClazzData(a,{name:a,parent:b,meta:c}),this},resolvePath:function(a){var b=this.getNamespace(),c=this.getManager();return b.getScope().search(b.adjustPath(a),function(a){return c.hasClazzData(a)?a:void 0})}});var c=function(a){a=a||{},this._clazzUID=0,this._metaProcessor=a.metaProcessor||null,this._baseClazz=a.baseClazz||null};_.extend(c.prototype,{CLAZZ_NAME:"Clazz{uid}",getBaseClazz:function(){return this._baseClazz},setBaseClazz:function(a){if(!_.isFunction(a))throw new Error("Base clazz must be a function!");return this._baseClazz=a,this},getMetaProcessor:function(){return this._metaProcessor},setMetaProcessor:function(a){if(!_.isFunction(a.process))throw new Error('Meta processor must have "process" method!');return this._metaProcessor=a,this},create:function(a){var b=a.name,c=a.parent||this.getBaseClazz()||null,d=a.meta,e=a.dependencies||[];return this.processMeta(this.createClazz({name:b,parent:c}),d,e)},createClazz:function(b){var c=b.name||this.generateName(),d=b.parent,e=b.body,f=e||function(){var a;return _.isFunction(this.__construct)?a=this.__construct.apply(this,_.toArray(arguments)):d&&(a=d.apply(this,_.toArray(arguments))),_.isUndefined(a)?void 0:a};if(d)for(var g in d)_.isFunction(d[g])?f[g]=d[g]:"_"===g[0]&&(f[g]=a);return _.extend(f,{__name:c,__parent:d||null}),f.prototype=_.extend(Object.create(d?d.prototype:{}),{constructor:f,__parent:d?d.prototype:null,__clazz:f,__proto:f.prototype}),f},processMeta:function(a,b,c){c=c||[];var d=this.getMetaProcessor();return d&&(_.isFunction(b)&&(b=b.apply(a,c)),_.isObject(b)&&d.process(a,b)),a},generateName:function(){return this.CLAZZ_NAME.replace("{uid}",++this._clazzUID)}});var d=function(){this._clazz={},this._clazzData={}};return _.extend(d.prototype,{setClazzData:function(a,b){return this._clazzData[a]=b,this},hasClazzData:function(a){return a in this._clazzData},getClazzData:function(a){if(!this.hasClazzData(a))throw new Error('Data does not exists for clazz "'+a+'"!');return this._clazzData[a]},getClazz:function(a,b){if(b=b||[],a in this._clazz)for(var c=this._clazz[a],d=0,e=c.length;e>d;++d){for(var f=!0,g=0,h=c[d][1].length;h>g;++g)if(c[d][1][g]!==b[g]){f=!1;break}if(f)return c[d][0]}throw new Error('Clazz "'+a+'" does not exists!')},hasClazz:function(a,b){if(b=b||[],a in this._clazz)for(var c=this._clazz[a],d=0,e=c.length;e>d;++d){for(var f=!0,g=0,h=c[d][1].length;h>g;++g)if(c[d][1][g]!==b[g]){f=!1;break}if(f)return!0}return!1},setClazz:function(a,b,c){if(!_.isFunction(b))throw new Error("Clazz must be a function!");return a in this._clazz||(this._clazz[a]=[]),this._clazz[a].push([b,c||[]]),this}}),{Clazz:b,Factory:c,Manager:d}}(),e=new b.Scope({defaultInjects:["clazz","namespace"]}),f=e.getRootNamespace(),g=new c.Manager,h=new c.Meta(g,f),i=new d.Manager,j=new d.Factory,k=new d.Clazz(i,j,f);return e.set("namespace",function(){return this}),e.set("meta",function(){return new c.Meta(g,this)}),e.set("clazz",function(){return new d.Clazz(i,j,this)}),f("ClazzJS","clazz","meta","namespace",function(b,c,d){c("Base",{_objectTypes:{clazz:function(a){return a},proto:function(a){return a.prototype}},_processors:{clazz:{constants:"Constants",clazz_properties:"Properties",clazz_methods:"Methods",clazz_events:"Events"},proto:{properties:"Properties",methods:"Methods",events:"Events"}},process:function(a,b){for(var d in this._processors){var e=this._objectTypes[d](a),f=this._processors[d];e.__interfaces||(e.__interfaces=[this.__name],_.extend(e,this.interface));for(var g in f){var h=f[g];_.isString(h)&&(h=c(h)),h.interface&&!e.__isInterfaceImplemented(h.__name)&&e.__implementInterface(h.__name,h.interface),h.process(e,b[g]||{},g)}}},addObjectType:function(a,b){return a in this._processors||(this._processors[a]=[]),this._objectTypes[a]=b,this},removeObjectType:function(a){return a in this._processors&&delete this._processors[a],delete this._objectTypes[a],this},addProcessor:function(a,b,c){return this._processors[a][b]=c,this},removeProcessor:function(a,b){return delete this._processors[a][b],this},"interface":{__isInterfaceImplemented:function(a){return-1!==this.__interfaces.indexOf(a)},__implementInterface:function(a,b){if(-1!==this.__interfaces.indexOf(a))throw new Error('Interface "'+a+'" is already implemented!');return this.__interfaces.push(a),_.extend(this,b),this},__collectAllPropertyValues:function(a,b){function c(a,b,d,e){e=[].concat(e);for(var f in b)e[0]&&f!==e[0]||(d>1&&_.isObject(b[f])?(f in a||(a[f]={}),c(a[f],b[f],d-1,e.slice(1))):f in a||(a[f]=b[f]))}var d=[];this.hasOwnProperty(a)&&d.push(this[a]),this.__proto&&this.__proto.hasOwnProperty(a)&&d.push(this.__proto[a]);for(var e=this.__parent;e;)e.hasOwnProperty(a)&&d.push(e[a]),e=e.__parent;for(var f=_.toArray(arguments).slice(2),g={},h=0,i=d.length;i>h;++h)c(g,d[h],b||1,f);return g}}}),c("Constants",{process:function(a,b){a.__constants={};for(var c in b)a.__constants[c]=b[c]},"interface":{__initConstants:function(){this.__constants={}},__getConstants:function(){return this.__collectAllPropertyValues("__constants",99)},__getConstant:function(){for(var a=_.toArray(arguments),b=this.__collectAllPropertyValues.apply(null,["__constants",99].concat(a)),c=0,d=a.length;d>c;++c){if(!(a[c]in b))throw new Error('Constant "'+a.splice(0,c).join(".")+'" does not exists!');b=a[c]}return b},__executeConstant:function(a,b){var c=this;if(_.isUndefined(b)&&(b=c.__getConstants()),_.isUndefined(a)){if(!(a in b))throw new Error('Constant "'+a+'" does not defined!');if(b=b[a],_.isObject(b))return function(a){return c.__getConstant(a,b)}}return b}}}),c("Events",{process:function(a,b){a.__events={};for(var c in b)for(var d in b[c])a.__addEventListener(c,d,b[c][d])},"interface":{__initEventsCallbacks:function(){this.__events={}},__emitEvent:function(a){var b=this.__getEventListeners(a);for(var c in b)b[c].apply(this,_.toArray(arguments).slice(1));return this},__addEventListener:function(a,b,c){if(this.__hasEventListener(a,b))throw new Error('Event listener for event "'+a+'" with name "'+b+'" is already exists!');return a in this.__events||(this.__events[a]={}),this.__events[a][b]=c,this},__removeEventListener:function(b,c){if(!this.hasEventCallback(b,c))throw new Error('There is no "'+b+(c?'"::"'+c:"")+'" event callback!');return this.__events[b][c]=a,this},__hasEventListener:function(a,b){return b in this.__getEventListeners(a)},__getEventListener:function(a,b){var c=this.__getEventListeners(a);if(!(b in c))throw new Error('Event listener for event "'+a+'" with name "'+b+'" does not exists!');return c[a][b]},__getEventListeners:function(a){return this.__collectAllPropertyValues.apply(null,["__events",2].concat(a||[]))}}}),c("Methods",{process:function(a,b){for(var c in b){if(!_.isFunction(b[c]))throw new Error('Method "'+c+'" must be a function!');a[c]=b[c]}}}),c("Properties",{_propertyMetaProcessor:"Property",process:function(a,b){a.__properties={},a.__setters={},a.__getters={};var c=this.getPropertyMetaProcessor();for(var d in b)c.process(a,b[d],d)},getPropertyMetaProcessor:function(){return _.isString(this._propertyMetaProcessor)&&(this._propertyMetaProcessor=c(this._propertyMetaProcessor)),this._propertyMetaProcessor},setPropertyMetaProcessor:function(a){return this._propertyMetaProcessor=a,this},"interface":{__initProperties:function(){this.__properties={},this.__setters={},this.__getters={};var a=this.__getPropertiesParam();for(var b in a)"default"in a[b]&&(this["_"+b]=a[b]["default"])},__setPropertiesParam:function(a){for(var b in a)this.__setPropertyParam(b,a[b]);return this},__getPropertiesParam:function(){return this.__collectAllPropertyValues("__properties",2)},__setPropertyParam:function(a,b,c){var d={};return _.isUndefined(c)?_.isObject(b)&&_.extend(d,b):d[b]=c,a=this.__adjustPropertyName(a),a in this.__properties||(this.__properties[a]={}),_.extend(this.__properties[a],d),this},__getPropertyParam:function(a,b){var c=this.__collectAllPropertyValues.apply(null,["__properties",2,a].concat(b||[]));return b?c[b]:c},__hasProperty:function(a){return a=this.__adjustPropertyName(a),"_"+a in this},__adjustPropertyName:function(a){return a.replace(/(?:_)\w/,function(a){return a[1].toUpperCase()})},__getPropertyValue:function(a){a=this.__adjustPropertyName(a);var b=_.toArray(arguments).slice(1);if(!("_"+a in this))throw new Error('Property "'+a+'" does not exists!');var c=this["_"+a],d=this.__getGetters(a);for(var e in d)c=d[e].call(this,c);for(var f=0,g=b.length;g>f;++f)c=c[b[f]];return c},__hasPropertyValue:function(a){a=this.__adjustPropertyName(a);for(var b=_.toArray(arguments).slice(1),c=this.__getPropertyValue(a),d=0,e=b.length;e>d;++d)if(!(b[d]in c)){return!1;var b,c,f,g,h,d,e,i,j}return!_.isUndefined(c)&&!_.isNull(c)},__isPropertyValue:function(b){var c=_.toArray(arguments).slice(1,-1),d=arguments.length>1?_.last(arguments):a,e=this.__getPropertyValue.apply(this,[b].concat(c));return _.isUndefined(d)?!!e:e===d},__clearPropertyValue:function(b){b=this.__adjustPropertyName(b);var c=_.toArray(arguments).slice(1),d=c.length?this.__getPropertyValue.apply(this,[b].concat(c.slice(0,-1))):this,e=c.length?_.last(c):"_"+b;if(!(e in d))throw new Error('Property "'+[b].concat(c)+'" does not exists!');var f=d[e],g=a;if(f.constructor==={}.constructor?g={}:_.isArray(f)&&(g=[]),d[e]=g,_.isFunction(this.__emitEvent)){if(f.constructor==={}.constructor)for(var h in f)this.__emitEvent("property."+[b].concat(c).join(".")+".item_removed",h,f[h]),this.__emitEvent("property."+[b].concat(c,h).join(".")+".removed",f[h]);else if(_.isArray(f))for(var i=0,j=f.length;j>i;++i)this.__emitEvent("property."+[b].concat(c).join(".")+".item_removed",i,f[i]),this.__emitEvent("property."+[b].concat(c,i).join(".")+".removed",f[i]);this.__emitEvent("property.cleared",c.length?[b].concat(c):b,f),this.__emitEvent("property."+[b].concat(c).join(".")+".cleared",f)}return this},__removePropertyValue:function(a){a=this.__adjustPropertyName(a);var b=_.toArray(arguments).slice(1),c=b.length?this.__getPropertyValue.apply(this,[a].concat(b.slice(0,-1))):this,d=b.length?_.last(b):"_"+a;if(!(d in c))throw new Error('Property "'+[a].concat(b)+'" does not exists!');var e=c[d];return delete c[d],_.isFunction(this.__emitEvent)&&(this.__emitEvent("property.removed",b.length?[a].concat(b):a,e),this.__emitEvent("property."+[a].concat(b).join(".")+".removed",e)),this},__setPropertyValue:function(a){if(a=this.__adjustPropertyName(a),!this.__hasProperty(a))throw new Error('Property "'+a+'" does not exists!');var b=_.toArray(arguments).slice(1,-1),c=_.last(arguments),d;if(b.length){var e=this;b.unshift("_"+a);for(var f=b.pop(),g=0,h=b.length;h>g;++g)_.isUndefined(e[b[g]])&&(e[b[g]]={}),e=e[b[g]];d=e[f],e[f]=c}else{var i=this.__getSetters(a);for(var j in i)c=i[j].call(this,c);d=this["_"+a],this["_"+a]=c}return _.isFunction(this.__emitEvent)&&(this.__emitEvent("property.changed",b.length?[a].concat(b):a,c,d),this.__emitEvent([a].concat(b),c,d)),this},__addSetter:function(a,b,c){if(!_.isFunction(c))throw new Error("Setter callback must be a function!");return a in this.__setters||(this.__setters[a]={}),this.__setters[a][b]=c,this},__getSetters:function(a){var b=this.__collectAllPropertyValues.apply(null,["__setters",1].concat(a||[]));return a?b[a]||{}:b},__addGetter:function(a,b){if(!_.isFunction(b))throw new Error("Getter callback must be a function!");return a in this.__getters||(this.__getters[a]=[]),this.__getters[a].push([weight,b]),this},__getGetters:function(a){var b=this.__collectAllPropertyValues.apply(null,["__getters",1].concat(a||[]));return a?b[a]||{}:b},__setData:function(a){for(var b in a)this.__hasProperty(b)&&this.__setPropertyValue(b,a[b]);return this},__getData:function(){var a={},b=this.__getPropertiesMeta();for(var c in b){var d=this.__getPropertyValue(c);if(_.isArray(d))for(var e=0,f=d.length;f>e;++e)_.isFunction(d[e].__getData)&&(d[e]=d[e].__getData());else if(d.constructor==={}.constructor)for(var g in d)_.isFunction(d[g].__getData)&&(d[g]=d[g].__getData());else _.isFunction(d.__getData)&&(d=d.__getData());a[c]=d}return a}}}),c("Property",{process:function(b,d,e){b["_"+e]=a,_.isArray(d)?d=3===d.length?{type:[d[0],d[2]],"default":d[1]}:{type:d}:_.isObject(d)||(d={"default":d}),"methods"in d||(d.methods=["get","set","has","is","clear","remove"]);for(var f in d)if(f in this._options){var g=this._options[f];_.isString(g)&&(g=c(g)),g.process(b,d[f],e)}},addOption:function(a,b){if(a in this._options)throw new Error('Option "'+a+'" is already exists!');return this._options[a]=b,this},hasOption:function(a){return a in this._options},removeOption:function(a){if(!(a in this._options))throw new Error('Option "'+a+'" does not exists!');return delete this._options[a],this},_options:{type:"Property/Type","default":"Property/Default",alias:"Property/Alias",methods:"Property/Methods",constraints:"Property/Constraints",converters:"Property/Converters",getters:"Property/Getters",setters:"Property/Setters"}}),d("Property","meta",function(a){a("Alias",{process:function(a,b,c){b&&a.__setPropertyParam(c,"aliases",[].concat(b))}}),a("Constraints",{SETTER_NAME:"__constraints__",process:function(a,b,c){a.__addSetter(c,this.SETTER_NAME,function(a){for(var c in b)if(!b[c].call(this,a))throw new Error('Constraint "'+c+'" was failed!');return a})}}),a("Converters",{SETTER_NAME:"__converters__",process:function(a,b,c){a.__addSetter(c,this.SETTER_NAME,function(a){for(var c in b)a=b[c].call(this,a);return a})}}),a("Default",{process:function(a,b,c){b&&a.__setPropertyParam(c,"default",b)}}),a("Getters",{process:function(a,b,c){for(var d in b)a.__addGetter(c,d,b[d])}}),a("Methods",{process:function(a,b,c,d){for(var e=0,f=b.length;f>e;++e)this.addMethodToObject(b[e],a,c);for(var d=a.__getPropertyParam(c,"aliases")||[],g=0,h=d.length;h>g;++g)for(var e=0,f=b.length;f>e;++e)this.addMethodToObject(b[e],a,c,d[g])},addMethodToObject:function(a,b,c,d){var e=this.createMethod(a,c,d);b[e.name]=e.body},createMethod:function(a,b,c){if(!(a in this._methods))throw new Error('Method "'+a+'" does not exists!');var d=this._methods[a](b,c);if(_.isFunction(d)){var e="undefined"!=typeof c?c:b;d={name:a+e[0].toUpperCase()+e.slice(1),body:d}}return d},addMethod:function(a,b){if(a in this._methods)throw new Error('Method "'+a+'" is already exists!');return this._methods[a]=b,this},hasMethod:function(a){return a in this._methods},removeMethod:function(a){if(!(a in this._methods))throw new Error('Method "'+a+'" does not exists!');return delete this._methods[a],this},_methods:{get:function(a){return function(){return this.__getPropertyValue.apply(this,[a].concat(_.toArray(arguments)))}},set:function(a){return function(){return this.__setPropertyValue.apply(this,[a].concat(_.toArray(arguments)))}},is:function(a,b){var c=_.isUndefined(b)?a:b;return{name:0!==c.indexOf("is")?"is"+c[0].toUpperCase()+c.slice(1):c,body:function(){return this.__isPropertyValue.apply(this,[a].concat(_.toArray(arguments)))}}},has:function(a){return function(){return this.__hasPropertyValue.apply(this,[a].concat(_.toArray(arguments)))}},clear:function(a){return function(){return this.__clearPropertyValue.apply(this,[a].concat(_.toArray(arguments)))}},remove:function(a){return function(){return this.__removePropertyValue.apply(this,[a].concat(_.toArray(arguments)))}}}}),a("Setters",{process:function(a,b,c){for(var d in b)a.__addSetter(c,d,b[d])}}),a("Type",{SETTER_NAME:"__type__",process:function(a,b,c){var d=this,e={};_.isArray(b)&&(e=b[1]||{},b=b[0]),a.__addSetter(c,this.SETTER_NAME,function(a){return _.isUndefined(a)||_.isNull(a)||(a=d.applyType(b,a,e,c)),a})},applyType:function(a,b,c,d){if(!(a in this._types))throw new Error('Property type "'+a+'" does not exists!');return this._types[a].call(this,b,c,d)},addType:function(a,b){if(a in this._types)throw new Error('Property type "'+a+'" is already exists!');return this._types[a]=b,this},hasType:function(a){return a in this._types},removeType:function(a){if(!(a in this._types))throw new Error('Property type "'+a+'" does not exists!');return delete this._types[a],this},setDefaultArrayDelimiter:function(a){if(!_.isString(a)&&!_.isRegExp(a))throw new Error("Delimiter must be a string or a regular expression!");return this._defaultArrayDelimiter=a,this},getDefaultArrayDelimiter:function(){return this._defaultArrayDelimiter},_defaultArrayDelimiter:/\s*,\s*/g,_types:{"boolean":function(a){return Boolean(a)},number:function(a,b,c){if(a=Number(a),"min"in b&&a<b.min)throw new Error('Value "'+a+'" of property "'+c+'" must not be less then "'+b.min+'"!');if("max"in b&&a>b.max)throw new Error('Value "'+a+'" of property "'+c+'" must not be greater then "'+b.max+'"!');return a},string:function(a,b,c){if(a=String(a),"pattern"in b&&!b.pattern.test(a))throw new Error('Value "'+a+'" of property "'+c+'" does not match pattern "'+b.pattern+'"!');if("variants"in b&&-1===b.variants.indexOf(a))throw new Error('Value "'+a+'" of property "'+c+'" must be one of "'+b.variants.join(", ")+'"!');return a},datetime:function(a,b,c){if(_.isNumber(a)&&!isNaN(a)?a=new Date(a):_.isString(a)&&(a=new Date(Date.parse(a))),a instanceof Date)throw new Error('Value of property "'+c+'" must have datetime type!');return a},array:function(a,b,c){var d,e,f;if(_.isString(a)&&(a=a.split(b.delimiter||this._defaultArrayDelimiter)),"element"in b)for(f=[].concat(b.element),d=0,e=a.length;e>d;++d)a[d]=this.applyType.call(this,a[d],f[0],f[1]||{},c+"."+d);return a},hash:function(a,b,c){var d,e;if(!_.isObject(a))throw new Error('Value of property "'+c+'" must have object type!');if("keys"in b)for(d in a)if(!(d in b.keys))throw new Error('Unsupported hash key "'+d+'" for property "'+c+'"!');if("element"in b){e=[].concat(b.element);for(d in a)a[d]=this.applyType.call(this,a[d],e[0],e[1]||{},c+"."+d)}return a},object:function(a,b,c){if("instanceof"in b&&(a instanceof b.instanceof||(a=new klass(a))),!_.isObject(a))throw new Error('Value of property "'+c+'" must have object type!');return a},"function":function(a,b,c){if(!_.isFunction("function"))throw new Error('Value of property "'+c+'" must have function type');return a}}})}),b("Base",function(){var a=0;return{clazz_methods:{create:function(){var a=arguments,b=new this(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],a[10]);return this.emit("object.create",b),b},emit:function(){return this.__emitEvent.apply(this,_.toArray(arguments))},"const":function(){return this.__executeConstant.apply(this,_.toArray(arguments))}},methods:{__construct:function(){this.__uid=++a;for(var b in this)0===b.indexOf("__init")&&_.isFunction(b)&&this[b]();_.isFunction(this.init)&&this.init.apply(this,_.toArray(arguments))},getUID:function(){return this.__uid},init:function(a){return this.__setData(a)},parent:function(a){var b=this;if(!b.__parent)throw new Error('Parent clazz does not exists for "'+this.__clazz.__name+'" clazz!');if(!_.isFunction(b.__parent[a]))throw new Error('Method "'+a+'" does not exists in clazz "'+this.__clazz.__name+'"!');return a=b.__parent[a],function(){return a.apply(this,_.toArray(arguments))}},emit:function(){return this.__emitEvent.apply(this,_.toArray(arguments))},"const":function(){return this.__clazz.__executeConstant.apply(this.__clazz,_.toArray(arguments))}}}})}),k.getFactory().setMetaProcessor(h("/ClazzJS/Base")).setBaseClazz(k("/ClazzJS/Base")),{Namespace:b,Clazz:d,Meta:c,namespace:f,clazz:k,meta:h}});
!function(a,b,c,d){if("function"==typeof define&&define.amd)define(b,c,d);else if("object"==typeof exports&&exports){for(var e=0,f=c.length;f>e;++e){var g=c[e];"string"==typeof g&&(g=g.replace(/([A-Z]+)/g,function(a){return"-"+a.toLowerCase()}).replace(/^-/,""),c[e]=require(g))}var h=d.apply(a,c);for(var i in h)exports[i]=h[i]}else{for(var e=0,f=c.length;f>e;++e){var g=c[e];if("string"==typeof g){if(!(g in a))throw new Error('"'+b+'" dependent on non exited module "'+g+'"!');c[e]=a[g]}}a[b]=d.apply(a,c)}}(new Function("return this")(),"ClazzJS",[],function(a){var b=function(){var a={},b=Object.prototype.toString,c=Array.prototype.slice;a.isUndefined=function(a){return void 0===a},a.isObject=function(a){return a===Object(a)},a.isNull=function(a){return null===a};for(var d=["Function","String","Number","Date","RegExp","Array"],e=0,f=d.length;f>e;++e)!function(c){a["is"+c]=function(a){return b.call(a)==="[object "+c+"]"}}(d[e]);return a.toArray=function(a){return c.call(a)},a.extend=function(a){for(var b=c.call(arguments,1),d=0,e=b.length;e>d;++d){var f=b[d];if(f)for(var g in f)a[g]=f[g]}return a},a.last=function(a){return a[a.length-1]},a}(),c=function(){var a=function(c,d){var e=function(a){var c=e.getScope().getNamespace(e.adjustPath(a));return arguments.length>1&&c.space.apply(c,b.toArray(arguments).slice(1)),c};return b.extend(e,a.prototype),e._scope=c,e._path=d,e._spaces=[],e._objects={},e};b.extend(a.prototype,{getPath:function(){return this._path},getScope:function(){return this._scope},adjustPath:function(a){return this._scope.isAbsolutePath(a)?this._scope.adjustPath(a):this._scope.concatPaths(this.getPath(),a)},get:function(a){return a in this._objects||(this._objects[a]=this._scope.get(a).call(this)),this._objects[a]},has:function(a){return this._scope.has(a)},space:function(){var a=this,c=b.toArray(arguments).slice(0,-1),d=b.last(arguments),e=[];c.length||(c=this._scope.getDefaultInjects());for(var f=0,g=c.length;g>f;++f)e[f]=this.get(c[f]);return this._spaces.push(function(){d.apply(a,e)}),this},executeSpace:function(){return this._spaces.length?(this._spaces.pop()(),!0):!1}});var c=function(a){a=a||{},this._innerDelimiter=a.innerDelimiter||"/",this._delimiters=a.delimiters||["\\","/","."],this._defaultInjects=a.defaultInjects||[],this._namespaces={},this._factories={},this._search=[]};return b.extend(c.prototype,{getInnerDelimiter:function(){return this._innerDelimiter},setInnerDelimiter:function(a){if(!this.hasDelimiter(a))throw new Error('Delimiter "'+a+'" does not supported!');return this._innerDelimiter=a,this},getDelimiters:function(){return this._delimiters},addDelimiter:function(a){if(this.hasDelimiter(a))throw new Error('Delimiter "'+a+'" is already exists!');return this},removeDelimiter:function(a){if(!this.hasDelimiter(a))throw new Error('Delimiter "'+a+'" does not exists!')},hasDelimiter:function(a){return-1!==this._delimiters.indexOf(a)},getNamespace:function(b){return b=this.adjustPath(b),b in this._namespaces||(this._namespaces[b]=a(this,b)),this._namespaces[b]},getRootNamespace:function(){return this.getNamespace(this.getRootPath())},getRootPath:function(){return this._innerDelimiter},adjustPath:function(a){var b=this.getInnerDelimiter(),c=this.getDelimiters();return a.replace(new RegExp("[\\"+c.join("\\")+"]","g"),b).replace(new RegExp(b+"+","g"),b).replace(new RegExp("(.+)"+b+"$"),function(a){return a})},isAbsolutePath:function(a){return 0===a.indexOf(this.getRootNamespace().getPath())},concatPaths:function(){return this.adjustPath(b.toArray(arguments).join(this.getInnerDelimiter()))},set:function(a,b){if(a in this._factories)throw new Error('Factory for object "'+a+'" is already exists!');return this._factories[a]=b,this},get:function(a){if(!(a in this._factories))throw new Error('Factory for object "'+a+'" does not exists!');return this._factories[a]},has:function(a){return a in this._factories},remove:function(a){return delete this._factories[a],this},getInSearchError:function(a){var b=new Error('Path "'+a+'" is in search state!');return b.inSearch=!0,b.path=a,b},isInSearchError:function(a){return a.inSearch},search:function(a,c){a=this.adjustPath(a);var d=c(a);if(!b.isUndefined(d))return d;for(var e=this.getInnerDelimiter(),f=a.split(e),g=f.pop();f.length;){var h=f.join(e);if(h in this._namespaces)for(var i=this._namespaces[h];i.executeSpace();)if(d=c(h+e+g),!b.isUndefined(d))return d;g=f.pop()}},getDefaultInjects:function(){return this._defaultInjects},addDefaultInject:function(a){if(-1!==this._defaultInjects.indexOf(a))throw new Error('Default inject "'+a+'" is already exists!');return this._defaultInjects.push(a),this},removeDefaultInject:function(a){var b=this._defaultInjects.indexOf(a);if(-1===b)throw new Error('Default inject "'+a+'" does not exists!');return this._defaultInjects.splice(b,1),this}}),{Namespace:a,Scope:c}}(),d=function(){var a=function(){this._processors={}};b.extend(a.prototype,{getProcessor:function(a){return this.checkProcessor(a),this._processors[a]},hasProcessor:function(a){return a in this._processors},setProcessor:function(a,c){return b.isFunction(c)&&(c={process:c}),"__name"in c||(c.__name=a),this._processors[a]=c,this},removeProcessor:function(a){this.checkProcessor(a);var b=this._processors[a];return delete this._processors[a],b},getProcessors:function(){return this._processors},setProcessors:function(a){for(var b in a)this.setProcessor(b,a[b]);return this},checkProcessor:function(a){if(!this.hasProcessor(a))throw new Error('Meta processor "'+a+'" does not exists!')}});var c=function(a,d){var e=function(a,c){return b.isUndefined(c)?e.get(a):e.set(a,c)};return b.extend(e,c.prototype),e._manager=a,e._namespace=d,e};return b.extend(c.prototype,{getManager:function(){return this._manager},getNamespace:function(){return this._namespace},get:function(a){var b=this.getManager(),c=this.resolveProcessorName(a);if(!c)throw new Error('Meta processor "'+a+'" does not exist!');return b.getProcessor(c)},set:function(a,b){var c=this.getNamespace(),d=this.getManager();return d.setProcessor(c.adjustPath(a),b),this},resolveProcessorName:function(a){var b=this.getManager(),c=this.getNamespace();return c.getScope().search(c.adjustPath(a),function(a){return b.hasProcessor(a)?a:void 0})}}),{Meta:c,Manager:a}}(),e=function(){var c=function(a,d,e){var f=function(a,c,d){var e=b.last(arguments);return b.isFunction(e)&&!e.prototype.__clazz||"[object Object]"===Object.prototype.toString.call(e)?(f.set(a,c,d),void 0):f.get(a,c,d)};return b.extend(f,c.prototype),f._manager=a,f._factory=d,f._namespace=e,f};b.extend(c.prototype,{getManager:function(){return this._manager},getFactory:function(){return this._factory},getNamespace:function(){return this._namespace},has:function(a){return!!this.resolveName(a)},get:function(c,d,e){b.isUndefined(e)&&b.isArray(d)&&(e=d,d=a);var f=this.resolvePath(c);if(!f)throw new Error('Clazz "'+c+'" does not exists!');e=e||[];var g=this.getManager();if(!g.hasClazz(f,d,e)){var h=this.getFactory(),i=g.getClazzData(f);g.setClazz(f,h.create({name:i.name,parent:d,metaParent:i.parent,meta:i.meta,dependencies:e,clazz:i.clazz}),d,e)}return g.getClazz(f,d,e)},set:function(c,d,e){b.isUndefined(e)&&(e=d,d=a);var f=this.getNamespace(),g=this.getManager();return b.isUndefined(e)&&(e=d,d=null),c=f.adjustPath(c),b.isString(d)&&(d=f.adjustPath(d)),g.setClazzData(c,{name:c,parent:d,meta:e,clazz:this}),this},resolvePath:function(a){var b=this.getNamespace(),c=this.getManager();return b.getScope().search(b.adjustPath(a),function(a){return c.hasClazzData(a)?a:void 0})}});var d=function(a){a=a||{},this._clazzUID=0,this._metaProcessor=a.metaProcessor||null,this._baseClazz=a.baseClazz||null};b.extend(d.prototype,{CLAZZ_NAME:"Clazz{uid}",getBaseClazz:function(){return this._baseClazz},setBaseClazz:function(a){if(!b.isFunction(a))throw new Error("Base clazz must be a function!");return this._baseClazz=a,this},getMetaProcessor:function(){return this._metaProcessor},setMetaProcessor:function(a){if(!b.isFunction(a.process))throw new Error('Meta processor must have "process" method!');return this._metaProcessor=a,this},create:function(a){var c=a.name||this.generateName(),d=a.parent,e=a.metaParent,f=a.meta||{},g=a.dependencies||[],h=a.clazz,i=this.createClazz();return i.__name=c,i.__clazz=h,b.isFunction(f)&&(f=f.apply(i,[i].concat(g))||{}),!f.parent&&e&&(f.parent=e),d=d||f.parent,b.isString(d)&&(d=[d]),b.isArray(d)&&(d=h.get.apply(h,d)),this.applyParent(i,d),i.prototype.__clazz=i,i.prototype.__proto=i.prototype,this.applyMeta(i,f),i},createClazz:function(){return function a(){var c;if(!(this instanceof a))throw new Error('Use "new" to create new "'+a.__name+'" instance!');return b.isFunction(this.__construct)?c=this.__construct.apply(this,b.toArray(arguments)):a.__parent&&(c=a.__parent.apply(this,b.toArray(arguments))),b.isUndefined(c)?void 0:c}},applyParent:function(c,d){if(d=d||this.getBaseClazz())for(var e in d)-1===["__name","__clazz"].indexOf(e)&&(b.isFunction(d[e])?c[e]=d[e]:"_"===e[0]&&(c[e]=a));return c.prototype=Object.create(d?d.prototype:{}),c.__parent=d||null,c.prototype.constructor=c,c.prototype.__parent=d?d.prototype:null,c},applyMeta:function(a,b){return this.getMetaProcessor().process(a,b),a},generateName:function(){return this.CLAZZ_NAME.replace("{uid}",++this._clazzUID)}});var e=function(){this._clazz={},this._clazzData={}};return b.extend(e.prototype,{setClazzData:function(a,b){return this._clazzData[a]=b,this},hasClazzData:function(a){return a in this._clazzData},getClazzData:function(a){if(!this.hasClazzData(a))throw new Error('Data does not exists for clazz "'+a+'"!');return this._clazzData[a]},getClazz:function(a,b,c){if(a in this._clazz)for(var d=this._clazz[a],e=0,f=d.length;f>e;++e)if(!b||d[e][1]===b){var g=!0;if(c)for(var h=0,i=d[e][2].length;i>h;++h)if(d[e][2][h]!==c[h]){g=!1;break}if(g)return d[e][0]}throw new Error('Clazz "'+a+'" does not exists!')},hasClazz:function(a,b,c){if(a in this._clazz)for(var d=this._clazz[a],e=0,f=d.length;f>e;++e)if(!b||d[e][1]===b){var g=!0;if(c)for(var h=0,i=d[e][2].length;i>h;++h)if(d[e][2][h]!==c[h]){g=!1;break}if(g)return!0}return!1},setClazz:function(a,c,d,e){if(!b.isFunction(c))throw new Error("Clazz must be a function!");return a in this._clazz||(this._clazz[a]=[]),this._clazz[a].push([c,d,e||[]]),this}}),{Clazz:c,Factory:d,Manager:e}}(),f=new c.Scope({defaultInjects:["clazz","namespace"]}),g=f.getRootNamespace(),h=new d.Manager,i=new d.Meta(h,g),j=new e.Manager,k=new e.Factory,l=new e.Clazz(j,k,g);return f.set("namespace",function(){return this}),f.set("meta",function(){return new d.Meta(h,this)}),f.set("clazz",function(){return new e.Clazz(j,k,this)}),g("ClazzJS","clazz","meta","namespace",function(c,d,e){d("Base",{_objectTypes:{clazz:function(a){return a},proto:function(a){return a.prototype}},_processors:{clazz:{},proto:{}},_optionProcessors:{clazz:{constants:"Constants",clazz_properties:"Properties",clazz_methods:"Methods",clazz_events:"Events"},proto:{properties:"Properties",methods:"Methods",events:"Events"}},process:function(a,c){a.__isClazz||b.extend(a,this.clazz_interface);var e=c.parent;if(e&&!a.__isSubclazzOf(e))throw new Error('Clazz "'+a.__name+'" must be subclazz of "'+e.__isClazz?e.__name:e+'"!');for(var f in this._objectTypes){var g=this._objectTypes[f](a);g.__interfaces||(g.__interfaces=["common"],b.extend(g,this.common_interface))}for(var f in this._processors){var g=this._objectTypes[f](a),h=this._processors[f];for(var i in h){var j=h[i];b.isString(j)&&(j=d(j)),j.interface&&!g.__isInterfaceImplemented(j.__name)&&g.__implementInterface(j.__name,j.interface),j.process(g,c)}}for(var f in this._optionProcessors){var g=this._objectTypes[f](a),h=this._optionProcessors[f];for(var k in h){var j=h[k];b.isString(j)&&(j=d(j)),j.interface&&!g.__isInterfaceImplemented(j.__name)&&g.__implementInterface(j.__name,j.interface),j.process(g,c[k]||{},k)}}},addObjectType:function(a,b){return a in this._processors||(this._processors[a]=[]),a in this._optionProcessors||(this._optionProcessors[a]={}),this._objectTypes[a]=b,this},removeObjectType:function(a){return a in this._processors&&delete this._processors,a in this._optionProcessors&&delete this._optionProcessors[a],delete this._objectTypes[a],this},hasProcessor:function(a,b){return b in this._processors[a]},addProcessor:function(a,b){if(b.__name in this._processors[a])throw new Error('Processor "'+b.__name+'" is already exists for object type "'+a+'"!');return this._processors[a][b.__name]=b,this},removeProcessor:function(a,b){if(!(b in this._processors[a]))throw new Error('Processor "'+b+'" does not exists for object type "'+a+'"!');return delete this._processors[a][b],this},hasOptionProcessor:function(a,b){return b in this._optionProcessors[a][b]},addOptionProcessor:function(a,b,c){return this._optionProcessors[a][b]=c,this},removeOptionProcessor:function(a,b){return delete this._optionProcessors[a][b],this},clazz_interface:{__isClazz:!0,__isSubclazzOf:function(a){for(var b=this;b;){if(b===a||b.__name===a)return!0;b=b.__parent}return!1}},common_interface:{__isInterfaceImplemented:function(a){return-1!==this.__interfaces.indexOf(a)},__implementInterface:function(a,c){if(-1!==this.__interfaces.indexOf(a))throw new Error('Interface "'+a+'" is already implemented!');return this.__interfaces.push(a),b.extend(this,c),this},__collectAllPropertyValues:function(a,c){function d(a,b,c,e){e=[].concat(e);for(var f in b)e[0]&&f!==e[0]||(c>1&&"[object Object]"===Object.prototype.toString.call(b[f])?(f in a||(a[f]={}),d(a[f],b[f],c-1,e.slice(1))):f in a||(a[f]=b[f]))}var e=[];this.hasOwnProperty(a)&&e.push(this[a]),this.__proto&&this.__proto.hasOwnProperty(a)&&e.push(this.__proto[a]);for(var f=this.__parent;f;)f.hasOwnProperty(a)&&e.push(f[a]),f=f.__parent;for(var g=b.toArray(arguments).slice(2),h={},i=0,j=e.length;j>i;++i)d(h,e[i],c||1,g);return h}}}),d("Constants",{process:function(a,b){a.__constants={};for(var c in b)a.__constants[c]=b[c]},"interface":{__initConstants:function(){this.__constants={}},__getConstants:function(){return this.__collectAllPropertyValues("__constants",99)},__getConstant:function(){for(var a=b.toArray(arguments),c=this.__collectAllPropertyValues.apply(this,["__constants",99].concat(a)),d=0,e=a.length;e>d;++d){if(!(a[d]in c))throw new Error('Constant "'+a.splice(0,d).join(".")+'" does not exists!');c=a[d]}return c},__executeConstant:function(a,c){var d=this;if(b.isUndefined(c)&&(c=d.__getConstants()),!b.isUndefined(a)){if(!(a in c))throw new Error('Constant "'+a+'" does not defined!');if(c=c[a],"[object Object]"===Object.prototype.toString.call(c))return function(a){return d.__executeConstant(a,c)}}return c}}}),d("Events",{process:function(a,b){a.__events={};for(var c in b)for(var d in b[c])a.__addEventListener(c,d,b[c][d])},"interface":{__initEventsCallbacks:function(){this.__events={}},__emitEvent:function(a){var c=this.__getEventListeners(a);for(var d in c)c[d].apply(this,b.toArray(arguments).slice(1));return this},__addEventListener:function(a,b,c){if(this.__hasEventListener(a,b))throw new Error('Event listener for event "'+a+'" with name "'+b+'" is already exists!');return a in this.__events||(this.__events[a]={}),this.__events[a][b]=c,this},__removeEventListener:function(b,c){if(!this.hasEventCallback(b,c))throw new Error('There is no "'+b+(c?'"::"'+c:"")+'" event callback!');return this.__events[b][c]=a,this},__hasEventListener:function(a,b){return b in this.__getEventListeners(a)},__getEventListener:function(a,b){var c=this.__getEventListeners(a);if(!(b in c))throw new Error('Event listener for event "'+a+'" with name "'+b+'" does not exists!');return c[a][b]},__getEventListeners:function(a){return this.__collectAllPropertyValues.apply(this,["__events",2].concat(a||[]))}}}),d("Methods",{process:function(a,c){for(var d in c){if(!b.isFunction(c[d]))throw new Error('Method "'+d+'" must be a function!');a[d]=c[d]}}}),d("Properties",{_propertyMetaProcessor:"Property",process:function(a,b){a.__properties={},a.__setters={},a.__getters={};var c=this.getPropertyMetaProcessor();for(var d in b)c.process(a,b[d],d)},getPropertyMetaProcessor:function(){return b.isString(this._propertyMetaProcessor)&&(this._propertyMetaProcessor=d(this._propertyMetaProcessor)),this._propertyMetaProcessor},setPropertyMetaProcessor:function(a){return this._propertyMetaProcessor=a,this},"interface":{__initProperties:function(){this.__properties={},this.__setters={},this.__getters={};var a=this.__getPropertiesParam();for(var c in a)if("default"in a[c]){var d=a[c].default;b.isFunction(d)&&(d=d.ca),this["_"+c]=a[c]["default"]}},__setPropertiesParam:function(a){for(var b in a)this.__setPropertyParam(b,a[b]);return this},__getPropertiesParam:function(){return this.__collectAllPropertyValues("__properties",2)},__setPropertyParam:function(a,c,d){var e={};return b.isUndefined(d)?b.isObject(c)&&b.extend(e,c):e[c]=d,a=this.__adjustPropertyName(a),a in this.__properties||(this.__properties[a]={}),b.extend(this.__properties[a],e),this},__getPropertyParam:function(a,b){var c=this.__collectAllPropertyValues.apply(this,["__properties",2,a].concat(b||[]));return b?c[b]:c},__hasProperty:function(a){return a=this.__adjustPropertyName(a),"_"+a in this},__adjustPropertyName:function(a){return a.replace(/(?:_)\w/,function(a){return a[1].toUpperCase()})},__getPropertyValue:function(a){a=this.__adjustPropertyName(a);var c=b.toArray(arguments).slice(1);if(!("_"+a in this))throw new Error('Property "'+a+'" does not exists!');var d=this["_"+a],e=this.__getGetters(a);for(var f in e)d=e[f].call(this,d);for(var g=0,h=c.length;h>g;++g){if(!c[g]in d)throw new Error('Property "'+[a].concat(c.slice(0,g)).join(".")+'" does not exists!');d=d[c[g]]}return d},__hasPropertyValue:function(a){a=this.__adjustPropertyName(a);for(var c=b.toArray(arguments).slice(1),d=this.__getPropertyValue(a),e=0,f=c.length;f>e;++e)if(!(c[e]in d))return!1;return!b.isUndefined(d)&&!b.isNull(d)},__isPropertyValue:function(c){var d=b.toArray(arguments).slice(1,-1),e=arguments.length>1?b.last(arguments):a,f=this.__getPropertyValue.apply(this,[c].concat(d));return b.isUndefined(e)?!!f:f===e},__clearPropertyValue:function(c){c=this.__adjustPropertyName(c);var d=b.toArray(arguments).slice(1),e=d.length?this.__getPropertyValue.apply(this,[c].concat(d.slice(0,-1))):this,f=d.length?b.last(d):"_"+c;if(!(f in e))throw new Error('Property "'+[c].concat(d)+'" does not exists!');var g=e[f],h=a;if(g.constructor==={}.constructor?h={}:b.isArray(g)&&(h=[]),e[f]=h,b.isFunction(this.__emitEvent)){if(g.constructor==={}.constructor)for(var i in g)this.__emitEvent("property."+[c].concat(d).join(".")+".item_removed",i,g[i]),this.__emitEvent("property."+[c].concat(d,i).join(".")+".removed",g[i]);else if(b.isArray(g))for(var j=0,k=g.length;k>j;++j)this.__emitEvent("property."+[c].concat(d).join(".")+".item_removed",j,g[j]),this.__emitEvent("property."+[c].concat(d,j).join(".")+".removed",g[j]);this.__emitEvent("property.cleared",d.length?[c].concat(d):c,g),this.__emitEvent("property."+[c].concat(d).join(".")+".cleared",g)}return this},__removePropertyValue:function(a){a=this.__adjustPropertyName(a);var c=b.toArray(arguments).slice(1),d=c.length?this.__getPropertyValue.apply(this,[a].concat(c.slice(0,-1))):this,e=c.length?b.last(c):"_"+a;if(!(e in d))throw new Error('Property "'+[a].concat(c)+'" does not exists!');var f=d[e];return delete d[e],b.isFunction(this.__emitEvent)&&(this.__emitEvent("property.removed",c.length?[a].concat(c):a,f),this.__emitEvent("property."+[a].concat(c).join(".")+".removed",f)),this},__setPropertyValue:function(a){if(a=this.__adjustPropertyName(a),!this.__hasProperty(a))throw new Error('Property "'+a+'" does not exists!');var c=b.toArray(arguments).slice(1,-1),d=b.last(arguments),e;if(c.length){var f=this;c.unshift("_"+a);for(var g=c.pop(),h=0,i=c.length;i>h;++h)b.isUndefined(f[c[h]])&&(f[c[h]]={}),f=f[c[h]];e=f[g],f[g]=d}else{var j=this.__getSetters(a);for(var k in j)d=j[k].call(this,d);e=this["_"+a],this["_"+a]=d}return b.isFunction(this.__emitEvent)&&(this.__emitEvent("property.changed",c.length?[a].concat(c):a,d,e),this.__emitEvent([a].concat(c),d,e)),this},__addSetter:function(a,c,d){if(!b.isFunction(d))throw new Error("Setter callback must be a function!");return a in this.__setters||(this.__setters[a]={}),this.__setters[a][c]=d,this},__getSetters:function(a){var b=this.__collectAllPropertyValues.apply(this,["__setters",1].concat(a||[]));return a?b[a]||{}:b},__addGetter:function(a,c){if(!b.isFunction(c))throw new Error("Getter callback must be a function!");return a in this.__getters||(this.__getters[a]=[]),this.__getters[a].push([weight,c]),this},__getGetters:function(a){var b=this.__collectAllPropertyValues.apply(this,["__getters",1].concat(a||[]));return a?b[a]||{}:b},__setData:function(a){for(var b in a)this.__hasProperty(b)&&this.__setPropertyValue(b,a[b]);return this},__getData:function(){var a={},c=this.__getPropertiesMeta();for(var d in c){var e=this.__getPropertyValue(d);if(b.isArray(e))for(var f=0,g=e.length;g>f;++f)b.isFunction(e[f].__getData)&&(e[f]=e[f].__getData());else if(e.constructor==={}.constructor)for(var h in e)b.isFunction(e[h].__getData)&&(e[h]=e[h].__getData());else b.isFunction(e.__getData)&&(e=e.__getData());a[d]=e}return a}}}),d("Property",{process:function(c,e,f){c["_"+f]=a,b.isArray(e)?e=3===e.length?{type:[e[0],e[2]],"default":e[1]}:{type:e}:b.isObject(e)||(e={"default":e}),"methods"in e||(e.methods=["get","set","has","is","clear","remove"]);for(var g in e)if(g in this._options){var h=this._options[g];b.isString(h)&&(h=d(h)),h.process(c,e[g],f)}},addOption:function(a,b){if(a in this._options)throw new Error('Option "'+a+'" is already exists!');return this._options[a]=b,this},hasOption:function(a){return a in this._options},removeOption:function(a){if(!(a in this._options))throw new Error('Option "'+a+'" does not exists!');return delete this._options[a],this},_options:{type:"Property/Type","default":"Property/Default",alias:"Property/Alias",methods:"Property/Methods",constraints:"Property/Constraints",converters:"Property/Converters",getters:"Property/Getters",setters:"Property/Setters"}}),e("Property","meta",function(a){a("Alias",{process:function(a,b,c){b&&a.__setPropertyParam(c,"aliases",[].concat(b))}}),a("Constraints",{SETTER_NAME:"__constraints__",process:function(a,b,c){var d=this;a.__addSetter(c,this.SETTER_NAME,function(a){return d.apply(a,b,c,this)})},apply:function(a,b,c,d){for(var e in b)if(!b[e].call(d,a,c))throw new Error('Constraint "'+e+'" was failed!');return a}}),a("Converters",{SETTER_NAME:"__converters__",process:function(a,b,c){var d=this;a.__addSetter(c,this.SETTER_NAME,function(a){return d.apply(a,b,c,this)})},apply:function(a,b,c,d){for(var e in b)a=b[e].call(d,a,c);return a}}),a("Default",{process:function(a,c,d){b.isUndefined(c)||a.__setPropertyParam(d,"default",c)}}),a("Getters",{process:function(a,b,c){for(var d in b)a.__addGetter(c,d,b[d])}}),a("Methods",{process:function(a,b,c,d){for(var e=0,f=b.length;f>e;++e)this.addMethodToObject(b[e],a,c);for(var d=a.__getPropertyParam(c,"aliases")||[],g=0,h=d.length;h>g;++g)for(var e=0,f=b.length;f>e;++e)this.addMethodToObject(b[e],a,c,d[g])},addMethodToObject:function(a,b,c,d){var e=this.createMethod(a,c,d);b[e.name]=e.body},createMethod:function(a,c,d){if(!(a in this._methods))throw new Error('Method "'+a+'" does not exists!');var e=this._methods[a](c,d);if(b.isFunction(e)){var f="undefined"!=typeof d?d:c;e={name:a+f[0].toUpperCase()+f.slice(1),body:e}}return e},addMethod:function(a,b){if(a in this._methods)throw new Error('Method "'+a+'" is already exists!');return this._methods[a]=b,this},hasMethod:function(a){return a in this._methods},removeMethod:function(a){if(!(a in this._methods))throw new Error('Method "'+a+'" does not exists!');return delete this._methods[a],this},_methods:{get:function(a){return function(){return this.__getPropertyValue.apply(this,[a].concat(b.toArray(arguments)))}},set:function(a){return function(){return this.__setPropertyValue.apply(this,[a].concat(b.toArray(arguments)))}},is:function(a,c){var d=b.isUndefined(c)?a:c;return{name:0!==d.indexOf("is")?"is"+d[0].toUpperCase()+d.slice(1):d,body:function(){return this.__isPropertyValue.apply(this,[a].concat(b.toArray(arguments)))}}},has:function(a){return function(){return this.__hasPropertyValue.apply(this,[a].concat(b.toArray(arguments)))}},clear:function(a){return function(){return this.__clearPropertyValue.apply(this,[a].concat(b.toArray(arguments)))}},remove:function(a){return function(){return this.__removePropertyValue.apply(this,[a].concat(b.toArray(arguments)))}}}}),a("Setters",{process:function(a,b,c){for(var d in b)a.__addSetter(c,d,b[d])}}),a("Type",{SETTER_NAME:"__type__",process:function(a,b,c){var d=this;a.__addSetter(c,this.SETTER_NAME,function(e){return d.apply(e,b,c,a)})},apply:function(a,c,d,e){if(b.isUndefined(a)||b.isNull(a))return a;var f={};if(b.isArray(c)&&(f=c[1]||{},c=c[0]),!(c in this._types))throw new Error('Property type "'+c+'" does not exists!');return this._types[c].call(this,a,f,d,e)},addType:function(a,b){if(a in this._types)throw new Error('Property type "'+a+'" is already exists!');return this._types[a]=b,this},hasType:function(a){return a in this._types},removeType:function(a){if(!(a in this._types))throw new Error('Property type "'+a+'" does not exists!');return delete this._types[a],this},setDefaultArrayDelimiter:function(a){if(!b.isString(a)&&!b.isRegExp(a))throw new Error("Delimiter must be a string or a regular expression!");return this._defaultArrayDelimiter=a,this},getDefaultArrayDelimiter:function(){return this._defaultArrayDelimiter},_defaultArrayDelimiter:/\s*,\s*/g,_types:{"boolean":function(a){return Boolean(a)},number:function(a,b,c){if(a=Number(a),"min"in b&&a<b.min)throw new Error('Value "'+a+'" of property "'+c+'" must not be less then "'+b.min+'"!');if("max"in b&&a>b.max)throw new Error('Value "'+a+'" of property "'+c+'" must not be greater then "'+b.max+'"!');return a},string:function(a,b,c){if(a=String(a),"pattern"in b&&!b.pattern.test(a))throw new Error('Value "'+a+'" of property "'+c+'" does not match pattern "'+b.pattern+'"!');if("variants"in b&&-1===b.variants.indexOf(a))throw new Error('Value "'+a+'" of property "'+c+'" must be one of "'+b.variants.join(", ")+'"!');return a},datetime:function(a,c,d){if(b.isNumber(a)&&!isNaN(a)?a=new Date(a):b.isString(a)&&(a=new Date(Date.parse(a))),!(a instanceof Date))throw new Error('Value of property "'+d+'" must have datetime type!');return a},array:function(a,c,d){var e,f,g;if(b.isString(a)&&(a=a.split(c.delimiter||this._defaultArrayDelimiter)),"element"in c)for(g=[].concat(c.element),e=0,f=a.length;f>e;++e)a[e]=this.apply.call(this,a[e],g,d+"."+e);return a},hash:function(a,c,d){var e,f;if(!b.isObject(a))throw new Error('Value of property "'+d+'" must have object type!');if("keys"in c)for(e in a)if(!(e in c.keys))throw new Error('Unsupported hash key "'+e+'" for property "'+d+'"!');if("element"in c){f=[].concat(c.element);for(e in a)a[e]=this.apply.call(this,a[e],f,d+"."+e)}return a},object:function(a,c,d,e){if(!b.isObject(a))throw new Error('Value of property "'+d+'" must have an object type!');if("instanceOf"in c){var f=c.instanceOf,g=e.__isClazz?e.__clazz:e.__clazz.__clazz;if(b.isString(f)&&(f=g.getNamespace().adjustPath(f),a.__clazz||(f=g(f))),a.__clazz?!a.__clazz.__isSubclazzOf(f):!(a instanceof f)){var h=f.__isClazz?f.__name:b.isString(f)?f:"another";throw new Error('Value of property "'+d+'" must be instance of '+h+" clazz!")}}return a},"function":function(a,c,d){if(!b.isFunction(a))throw new Error('Value of property "'+d+'" must have function type');return a}}})}),c("Base",function(){var a=0;return{clazz_methods:{create:function(){var a=arguments,b=new this(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],a[10]);return this.emit("object.create",b),b},emit:function(){return this.__emitEvent.apply(this,b.toArray(arguments))},"const":function(){return this.__executeConstant.apply(this,b.toArray(arguments))}},methods:{__construct:function(){this.__uid=++a;for(var c in this)0===c.indexOf("__init")&&b.isFunction(this[c])&&this[c]();b.isFunction(this.init)&&this.init.apply(this,b.toArray(arguments))},getUID:function(){return this.__uid},init:function(a){return this.__setData(a)},parent:function(a){var c=this;if(!c.__parent)throw new Error('Parent clazz does not exists for "'+this.__clazz.__name+'" clazz!');if(!b.isFunction(c.__parent[a]))throw new Error('Method "'+a+'" does not exists in clazz "'+this.__clazz.__name+'"!');return a=c.__parent[a],function(){return a.apply(this,b.toArray(arguments))}},emit:function(){return this.__emitEvent.apply(this,b.toArray(arguments))},"const":function(){return this.__clazz.__executeConstant.apply(this.__clazz,b.toArray(arguments))}}}})}),l.getFactory().setMetaProcessor(i("/ClazzJS/Base")).setBaseClazz(l("/ClazzJS/Base")),{Namespace:c,Clazz:e,Meta:d,namespace:g,clazz:l,meta:i,_:b}});
//# sourceMappingURL=dist/ClazzJS.min.map

@@ -7,3 +7,3 @@ "use strict";

grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-jsbeautifier')
grunt.loadNpmTasks('grunt-jsbeautifier');

@@ -18,2 +18,4 @@ grunt.initConfig({

"src/miniunderscore.js",
"src/core/Namespace/.prefix",

@@ -20,0 +22,0 @@ "src/core/Namespace/*.js",

{
"name": "clazz-js",
"title": "ClazzJS",
"version": "0.3.0",
"version": "0.3.1",
"description": "Portable JavaScript library for class-style OOP programming",

@@ -6,0 +6,0 @@ "author": {

ClazzJS
=======
Portable JavaScript library for class-style OOP programming
ClazzJS is portable JavaScript library for class-style OOP programming. It's main goal to provide expressive DSL to
write your JavaScript programs in easy-to-understand, well-known, convenient and flexible clazz base manner. It's works
well both on client and server sides.
Documentation is coming soon. Until that look at usage example: http://plnkr.co/edit/c5Xveb
Features include:
- Single inheritance
- Expressive, extensible DSL for declaring of your class
- Methods generation
- Events emitting
- Object properties changes observing
- Namespaces
You'll find the example bellow to have a common idea what I'm talking about.
**Caution:**
> This library is still under development. I don't think that it's API will be changed much. But you must take this into considiration.
Documentation
-------------
1. [Installation](docs/1_Installation.md)
Example
--------
Main goal of this example is to give you a common idea about ClazzJS. It's not discover all features of the library. Online working version of this example is available on plnkr: [http://plnkr.co/edit/c5Xveb](http://plnkr.co/edit/c5Xveb). Feel free to play around with it!
Declaring of common Person clazz:
```js
clazz("Person", {
constants: {
SEX: ['male', 'female']
},
properties: {
name: {
type: 'string',
methods: ['get']
},
phone: {
type: ['string', {
pattern: /\d{1,2}-\d{3}-\d{5,7}/
}]
},
birthday: {
type: 'datetime',
constratins: {
inPast: function(birthday) {
return birthday.getTime() < Date.now();
}
}
},
sex: {
type: 'string',
methods: ['get', 'set', 'is'],
converters: {
toFull: function(sex) {
switch(sex.toLowerCase()) {
case 'm': sex = 'male'; break;
case 'f': sex = 'female'; break;
}
return sex;
}
},
constraints: {
existedSex: function(sex) {
return -1 !== this.const('SEX').indexOf(sex);
}
}
}
},
methods: {
getAge: function() {
return (new Date()).getFullYear() - this.getBirthday().getFullYear();
}
}
});
```
Declaring of Teacher clazz inherited from Person:
```js
clazz('Teacher', 'Person', {
constants: {
SUBJECT: ['physics', 'literature', 'mathematics']
},
properties: {
subject: {
type: 'string',
constraints: {
existedSubject: function(subject) {
return -1 !== this.const('SUBJECT').indexOf(subject);
}
}
}
}
});
```
Creation and manipulation of instances:
```js
// Create just common person - John (without 'new' operator)
var john = clazz('Person').create({
name: 'John Stewart',
sex: 'M',
phone: '1-925-123567',
birthday: "1989-12-13"
});
john instanceof clazz("Person"); // true
john.getName(); // 'John Stewart'
john.getAge(); // 24
john.getSex(); // 'male'
john.getPhone(); // 1-925-123567
john.setPhone('7-925-1'); // Throw phone pattern fail error with message:
// 'Value "7-925-1" does not match
// pattern "/\d{1,2}-\d{3}-\d{5,7}/"'
john.isSex("male"); // true
john.isSex("female"); // false
john.setSex('unsupportedSex'); // Throw existedSex constraint fail error with message:
// 'Constraint "existedSex" was failed!'
john.setSex('female'); // Successfully change sex of John
john.getSex(); // 'female'
john.isSex("male"); // false
john.isSex("female"); // true
john.getBirthday() instanceof Date; // true
john.getBirthday().getMonth(); // 12
john.getBirthday().getFullYear(); // 189
// Create math teacher - Mr. George Smith. (with 'new' operator)
var mathTeacher = new clazz('Teacher')({
name: 'George Smith',
sex: 'male',
birthday: '1973-12-34',
subject: 'mathematics'
});
mathTeacher instanceof clazz('Person'); // true
mathTeacher instanceof clazz('Teacher')); // true
mathTeacher.getName(); // John Smith
```
License
-------
Copyright (c) 2013 Aleksey Podskrebyshev. Licensed under the MIT license.

@@ -28,3 +28,3 @@ clazz('Base', function() {

for (var method in this) {
if (0 === method.indexOf('__init') && _.isFunction(method)) {
if (0 === method.indexOf('__init') && _.isFunction(this[method])) {
this[method]();

@@ -31,0 +31,0 @@ }

@@ -9,2 +9,7 @@ meta('Base', {

_processors: {
clazz: {},
proto: {}
},
_optionProcessors: {
clazz: {

@@ -25,2 +30,23 @@ constants: 'Constants',

if (!clazz.__isClazz) {
_.extend(clazz, this.clazz_interface);
}
var parent = metaData.parent;
if (parent) {
if (!clazz.__isSubclazzOf(parent)) {
throw new Error('Clazz "' + clazz.__name + '" must be subclazz of "' + parent.__isClazz ? parent.__name : parent + '"!');
}
}
for (var objectType in this._objectTypes) {
var object = this._objectTypes[objectType](clazz);
if (!object.__interfaces) {
object.__interfaces = ['common'];
_.extend(object, this.common_interface);
}
}
for (var objectType in this._processors) {

@@ -31,7 +57,23 @@

if (!object.__interfaces) {
object.__interfaces = [this.__name];
_.extend(object, this.interface);
for (var name in processors) {
var processor = processors[name];
if (_.isString(processor)) {
processor = meta(processor);
}
if (processor.interface && !object.__isInterfaceImplemented(processor.__name)) {
object.__implementInterface(processor.__name, processor.interface);
}
processor.process(object, metaData);
}
}
for (var objectType in this._optionProcessors) {
var object = this._objectTypes[objectType](clazz);
var processors = this._optionProcessors[objectType];
for (var option in processors) {

@@ -57,2 +99,5 @@ var processor = processors[option];

}
if (!(name in this._optionProcessors)) {
this._optionProcessors[name] = {};
}
this._objectTypes[name] = getter;

@@ -64,4 +109,7 @@ return this;

if (name in this._processors) {
delete this._processors[name];
delete this._processors;
}
if (name in this._optionProcessors) {
delete this._optionProcessors[name];
}
delete this._objectTypes[name];

@@ -71,15 +119,56 @@ return this;

addProcessor: function(objectType, option, processor) {
this._processors[objectType][option] = processor;
hasProcessor: function(objectType, name) {
return name in this._processors[objectType];
},
addProcessor: function(objectType, processor) {
if (processor.__name in this._processors[objectType]) {
throw new Error('Processor "' + processor.__name + '" is already exists for object type "' + objectType + '"!');
}
this._processors[objectType][processor.__name] = processor;
return this;
},
removeProcessor: function(objectType, option) {
delete this._processors[objectType][option];
removeProcessor: function(objectType, name) {
if (!(name in this._processors[objectType])) {
throw new Error('Processor "' + name + '" does not exists for object type "' + objectType + '"!');
}
delete this._processors[objectType][name];
return this;
},
hasOptionProcessor: function(objectType, option) {
return option in this._optionProcessors[objectType][option];
},
interface: {
addOptionProcessor: function(objectType, option, processor) {
this._optionProcessors[objectType][option] = processor;
return this;
},
removeOptionProcessor: function(objectType, option) {
delete this._optionProcessors[objectType][option];
return this;
},
clazz_interface: {
__isClazz: true,
__isSubclazzOf: function(parent) {
var clazzParent = this;
while (clazzParent) {
if (clazzParent === parent || clazzParent.__name === parent) {
return true;
}
clazzParent = clazzParent.__parent;
}
return false;
}
},
common_interface: {
__isInterfaceImplemented: function(interfaceName) {

@@ -136,3 +225,3 @@ return -1 !== this.__interfaces.indexOf(interfaceName);

if (level > 1 && _.isObject(container[name])) {
if (level > 1 && Object.prototype.toString.call(container[name]) === '[object Object]') {
if (!(name in collector)) {

@@ -139,0 +228,0 @@ collector[name] = {};

@@ -24,3 +24,3 @@ meta('Constants', {

var fields = _.toArray(arguments)
var constant = this.__collectAllPropertyValues.apply(null, ['__constants', 99].concat(fields));
var constant = this.__collectAllPropertyValues.apply(this, ['__constants', 99].concat(fields));

@@ -44,3 +44,3 @@ for (var i = 0, ii = fields.length; i < ii; ++i) {

if (_.isUndefined(name)) {
if (!_.isUndefined(name)) {
if (!(name in constants)) {

@@ -51,5 +51,5 @@ throw new Error('Constant "' + name + '" does not defined!');

if (_.isObject(constants)) {
if (Object.prototype.toString.call(constants) === '[object Object]') {
return function(name) {
return self.__getConstant(name, constants)
return self.__executeConstant(name, constants)
}

@@ -56,0 +56,0 @@ }

@@ -68,5 +68,5 @@ meta('Events', {

__getEventListeners: function(event) {
return this.__collectAllPropertyValues.apply(null, ['__events', 2].concat(event || []));
return this.__collectAllPropertyValues.apply(this, ['__events', 2].concat(event || []));
}
}
});

@@ -40,2 +40,6 @@ meta('Properties', {

if ('default' in propertiesParams[property]) {
var defaultValue = propertiesParams[property].default;
if (_.isFunction(defaultValue)) {
defaultValue = defaultValue.ca
}
this['_' + property] = propertiesParams[property]['default'];

@@ -79,3 +83,3 @@ }

__getPropertyParam: function(property, param) {
var params = this.__collectAllPropertyValues.apply(null, ['__properties', 2, property].concat(param || []));
var params = this.__collectAllPropertyValues.apply(this, ['__properties', 2, property].concat(param || []));
return param ? params[param] : params;

@@ -111,2 +115,5 @@ },

for (var i = 0, ii = fields.length; i < ii; ++i) {
if (!(fields[i]) in value) {{
throw new Error('Property "' + [property].concat(fields.slice(0,i)).join('.') + '" does not exists!');
}}
value = value[fields[i]];

@@ -127,43 +134,2 @@ }

return false;
property = this.__adjustPropertyName(property);
if (!this.__hasProperty(property)) {
throw new Error('Property "' + property + '" does not exists!');
}
var fields = _.toArray(arguments).slice(1, -1);
var value = _.last(arguments);
var oldValue;
if (fields.length) {
var container = this['_' + property];
var field = fields.pop();
for (var i = 0, ii = fields.length; i < ii; ++i) {
if (!(fields[i] in container)) {
container[fields[i]] = {};
}
container = container[fields[i]];
}
oldValue = container[field];
container[field] = value;
}
else {
var setters = this.__getSetters(property);
for (var name in setters) {
value = setters[name].call(this, value);
}
oldValue = this['_' + property];
this['_' + property] = value;
}
// Event emitting
if (_.isFunction(this.__emitEvent)) {
this.__emitEvent('property.changed', fields.length ? [property].concat(fields) : property, value, oldValue);
this.__emitEvent('property.' + fields.length ? [property].concat(fields) : property + '.changed', value, oldValue);
}
return this;
}

@@ -318,3 +284,3 @@ }

__getSetters: function(property) {
var setters = this.__collectAllPropertyValues.apply(null, ['__setters', 1].concat(property || []));
var setters = this.__collectAllPropertyValues.apply(this, ['__setters', 1].concat(property || []));
return property ? (setters[property] || {}) : setters;

@@ -336,3 +302,3 @@ },

__getGetters: function(property) {
var getters = this.__collectAllPropertyValues.apply(null, ['__getters', 1].concat(property || []));
var getters = this.__collectAllPropertyValues.apply(this, ['__getters', 1].concat(property || []));
return property ? (getters[property] || {}) : getters;

@@ -339,0 +305,0 @@ },

@@ -6,12 +6,18 @@ meta('Constraints', {

process: function(object, constraints, property) {
var self = this;
object.__addSetter(property, this.SETTER_NAME, function(value) {
for (var name in constraints) {
if (!constraints[name].call(this, value)) {
throw new Error('Constraint "' + name + '" was failed!');
}
return self.apply(value, constraints, property, this);
});
},
apply: function(value, constraints, property, object) {
for (var name in constraints) {
if (!constraints[name].call(object, value, property)) {
throw new Error('Constraint "' + name + '" was failed!');
}
return value;
});
}
return value;
}
});

@@ -6,9 +6,15 @@ meta('Converters', {

process: function(object, converters, property) {
var self = this;
object.__addSetter(property, this.SETTER_NAME , function(value) {
for (var name in converters) {
value = converters[name].call(this, value);
}
return value;
return self.apply(value, converters, property, this);
});
},
apply: function(value, converters, property, object) {
for (var name in converters) {
value = converters[name].call(object, value, property);
}
return value;
}
});
meta('Default', {
process: function(object, defaultValue, property) {
if (defaultValue) {
if (!_.isUndefined(defaultValue)) {
object.__setPropertyParam(property, 'default', defaultValue);

@@ -6,0 +6,0 @@ }

@@ -6,4 +6,13 @@ meta('Type', {

process: function(object, type, property) {
var self = this;
var self = this;
object.__addSetter(property, this.SETTER_NAME, function(value) {
return self.apply(value, type, property, object);
});
},
apply: function(value, type, property, object) {
if (_.isUndefined(value) || _.isNull(value)) {
return value;
}
var params = {};

@@ -16,11 +25,2 @@

object.__addSetter(property, this.SETTER_NAME, function(value) {
if (!_.isUndefined(value) && !_.isNull(value)) {
value = self.applyType(type, value, params, property);
}
return value;
});
},
applyType: function(type, value, params, property) {
if (!(type in this._types)) {

@@ -30,3 +30,3 @@ throw new Error('Property type "' + type + '" does not exists!');

return this._types[type].call(this, value, params, property);
return this._types[type].call(this, value, params, property, object);
},

@@ -102,3 +102,3 @@

if (value instanceof Date) {
if (!(value instanceof Date)) {
throw new Error('Value of property "' + property + '" must have datetime type!');

@@ -118,3 +118,3 @@ }

for (i = 0, ii = value.length; i < ii; ++i) {
value[i] = this.applyType.call(this, value[i], type[0], type[1] || {}, property + '.' + i);
value[i] = this.apply.call(this, value[i], type, property + '.' + i);
}

@@ -141,3 +141,3 @@ }

for (key in value) {
value[key] = this.applyType.call(this, value[key], type[0], type[1] || {}, property + '.' + key);
value[key] = this.apply.call(this, value[key], type, property + '.' + key);
}

@@ -147,12 +147,30 @@ }

},
object: function(value, params, property) {
object: function(value, params, property, object) {
if ('instanceof' in params) {
if (!(value instanceof params.instanceof)) {
value = new klass(value);
}
if (!_.isObject(value)) {
throw new Error('Value of property "' + property + '" must have an object type!');
}
if (!_.isObject(value)) {
throw new Error('Value of property "' + property + '" must have object type!');
if ('instanceOf' in params) {
var instanceOf = params.instanceOf;
var clazzClazz = object.__isClazz ? object.__clazz : object.__clazz.__clazz;
if (_.isString(instanceOf)) {
instanceOf = clazzClazz.getNamespace().adjustPath(instanceOf);
if (!value.__clazz) {
instanceOf = clazzClazz(instanceOf);
}
}
if (value.__clazz ? !value.__clazz.__isSubclazzOf(instanceOf) : !(value instanceof instanceOf)) {
var className = instanceOf.__isClazz
? instanceOf.__name
: (_.isString(instanceOf) ? instanceOf : 'another');
throw new Error('Value of property "' + property + '" must be instance of ' + className + ' clazz!');
}
}

@@ -163,3 +181,3 @@

function: function(value, params, property) {
if (!_.isFunction('function')) {
if (!_.isFunction(value)) {
throw new Error('Value of property "' + property + '" must have function type');

@@ -166,0 +184,0 @@ }

var Clazz = function(manager, factory, namespace) {
var self = function(name, parentOrDependencies, meta) {
var self = function(name, parent, metaOrDependencies) {
var last = _.last(arguments);
if (!_.isFunction(last) && Object.prototype.toString.call(last) !== '[object Object]') {
return self.get(name, /* dependencies */ parentOrDependencies);
if ((!_.isFunction(last) || last.prototype.__clazz) && Object.prototype.toString.call(last) !== '[object Object]') {
return self.get(name, parent, /* dependencies */ metaOrDependencies);
}
self.set(name, /* parent */ parentOrDependencies, meta);
self.set(name, parent, /* meta */ metaOrDependencies);
};

@@ -39,4 +39,9 @@

get: function(originalName, dependencies) {
get: function(originalName, parent, dependencies) {
if (_.isUndefined(dependencies) && _.isArray(parent)) {
dependencies = parent;
parent = undefined;
}
var name = this.resolvePath(originalName);

@@ -52,3 +57,3 @@

if (!manager.hasClazz(name, dependencies)) {
if (!manager.hasClazz(name, parent, dependencies)) {

@@ -60,8 +65,10 @@ var factory = this.getFactory();

name: clazzData.name,
parent: clazzData.parent,
parent: parent,
metaParent: clazzData.parent,
meta: clazzData.meta,
dependencies: dependencies
}), dependencies);
dependencies: dependencies,
clazz: clazzData.clazz
}), parent, dependencies);
}
return manager.getClazz(name, dependencies);
return manager.getClazz(name, parent, dependencies);
},

@@ -71,2 +78,7 @@

if (_.isUndefined(meta)) {
meta = parent;
parent = undefined;
}
var namespace = this.getNamespace();

@@ -82,6 +94,11 @@ var manager = this.getManager();

if (_.isString(parent)) {
parent = namespace.adjustPath(parent);
}
manager.setClazzData(name, {
name: name,
parent: parent,
meta: meta
meta: meta,
clazz: this
});

@@ -88,0 +105,0 @@

@@ -37,26 +37,57 @@ var Factory = function(options) {

create: function(params) {
create: function(data) {
var name = params.name;
var parent = params.parent || this.getBaseClazz() || null;
var meta = params.meta;
var dependencies = params.dependencies || [];
var name = data.name || this.generateName();
var parent = data.parent;
var metaParent = data.metaParent;
var meta = data.meta || {};
var dependencies = data.dependencies || [];
var clazz = data.clazz;
return this.processMeta(this.createClazz({ name: name, parent: parent }), meta, dependencies);
},
var newClazz = this.createClazz();
createClazz: function(params) {
newClazz.__name = name;
newClazz.__clazz = clazz;
var name = params.name || this.generateName();
var parent = params.parent;
var body = params.body;
if (_.isFunction(meta)) {
meta = meta.apply(newClazz, [newClazz].concat(dependencies)) || {};
}
var clazz = body || function() {
if (!meta.parent && metaParent) {
meta.parent = metaParent;
}
parent = parent || meta.parent;
if (_.isString(parent)) {
parent = [parent];
}
if (_.isArray(parent)) {
parent = clazz.get.apply(clazz, parent);
}
this.applyParent(newClazz, parent);
newClazz.prototype.__clazz = newClazz;
newClazz.prototype.__proto = newClazz.prototype;
this.applyMeta(newClazz, meta);
return newClazz;
},
createClazz: function() {
return function self() {
var result;
if (!(this instanceof self)) {
throw new Error('Use "new" to create new "' + self.__name + '" instance!');
}
if (_.isFunction(this.__construct)) {
result = this.__construct.apply(this, _.toArray(arguments));
}
else if (parent) {
result = parent.apply(this, _.toArray(arguments));
else if (self.__parent) {
result = self.__parent.apply(this, _.toArray(arguments));
}

@@ -68,6 +99,14 @@

};
},
applyParent: function(clazz, parent) {
parent = parent || this.getBaseClazz();
if (parent) {
for (var property in parent) {
if (_.isFunction(parent[property])) {
if (-1 !== ['__name', '__clazz'].indexOf(property)) {
continue;
}
else if (_.isFunction(parent[property])) {
clazz[property] = parent[property];

@@ -81,13 +120,7 @@ }

_.extend(clazz, {
__name: name,
__parent: parent || null
});
clazz.prototype = Object.create(parent ? parent.prototype : {});
clazz.prototype = _.extend(Object.create(parent ? parent.prototype : {}), {
constructor: clazz,
__parent: parent ? parent.prototype : null,
__clazz: clazz,
__proto: clazz.prototype
});
clazz.__parent = parent || null;
clazz.prototype.constructor = clazz;
clazz.prototype.__parent = parent ? parent.prototype : null;

@@ -97,17 +130,4 @@ return clazz;

processMeta: function(clazz, meta, dependencies) {
dependencies = dependencies || []
var metaProcessor = this.getMetaProcessor();
if (metaProcessor) {
if (_.isFunction(meta)) {
meta = meta.apply(clazz, dependencies);
}
if (_.isObject(meta)) {
metaProcessor.process(clazz, meta);
}
}
applyMeta: function(clazz, meta) {
this.getMetaProcessor().process(clazz, meta);
return clazz;

@@ -114,0 +134,0 @@ },

@@ -24,4 +24,3 @@ var Manager = function() {

getClazz: function(name, dependencies) {
dependencies = dependencies || [];
getClazz: function(name, parent, dependencies) {

@@ -32,8 +31,15 @@ if (name in this._clazz) {

for (var i = 0, ii = clazzes.length; i < ii; ++i) {
if (parent) {
if (clazzes[i][1] !== parent) {
continue;
}
}
var isFound = true;
for (var j = 0, jj = clazzes[i][1].length; j < jj; ++j) {
if (clazzes[i][1][j] !== dependencies[j]) {
isFound = false;
break;
if (dependencies) {
for (var j = 0, jj = clazzes[i][2].length; j < jj; ++j) {
if (clazzes[i][2][j] !== dependencies[j]) {
isFound = false;
break;
}
}

@@ -51,4 +57,3 @@ }

hasClazz: function(name, dependencies) {
dependencies = dependencies || [];
hasClazz: function(name, parent, dependencies) {

@@ -59,9 +64,17 @@ if (name in this._clazz) {

for (var i = 0, ii = clazzes.length; i < ii; ++i) {
if (parent) {
if (clazzes[i][1] !== parent) {
continue;
}
}
var isFound = true;
for (var j = 0, jj = clazzes[i][1].length; j < jj; ++j) {
if (clazzes[i][1][j] !== dependencies[j]) {
isFound = false;
break;
if (dependencies) {
for (var j = 0, jj = clazzes[i][2].length; j < jj; ++j) {
if (clazzes[i][2][j] !== dependencies[j]) {
isFound = false;
break;
}
}
}

@@ -78,3 +91,3 @@

setClazz: function(name, clazz, dependencies) {
setClazz: function(name, clazz, parent, dependencies) {
if (!_.isFunction(clazz)) {

@@ -88,3 +101,3 @@ throw new Error('Clazz must be a function!');

this._clazz[name].push([clazz, dependencies || []]);
this._clazz[name].push([clazz, parent, dependencies || []]);

@@ -91,0 +104,0 @@ return this;

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc