Comparing version 0.4.1 to 0.5.0
{ | ||
"name": "ClazzJS", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"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={},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.isSimpleObject=function(a){return"[object Object]"===b.call(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.construct=function(a,b){var c=function(){return a.apply(this,b)};return c.prototype=a.prototype,new c},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}),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;return this instanceof a?(b.isFunction(a.__construct)&&(c=a.__construct.apply(this,b.toArray(arguments))),b.isUndefined(c)?void 0:c):b.construct(a,b.toArray(arguments))}},applyParent:function(c,d){if(d=d||this.getBaseClazz())for(var e in d)e in c||(b.isFunction(d[e])?c[e]=d[e]:"_"===e[0]&&(c[e]=a));return c.prototype=b.extend(Object.create(d?d.prototype:{}),c.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",{_processors:{constants:"Constants",properties:"Properties",methods:"Methods",events:"Events"},process:function(a,c){a.__isClazz||b.extend(a,this.clazz_interface),a.__interfaces||(a.__interfaces=[],a.prototype.__interfaces=[],b.extend(a,this.common_interface),b.extend(a.prototype,this.common_interface)),a.__metaProcessors=c.meta_processors||{};var d=c.parent;if(d&&!a.__isSubclazzOf(d))throw new Error('Clazz "'+a.__name+'" must be subclazz of "'+d.__isClazz?d.__name:d+'"!');var e=a.__getMetaProcessors();for(var f in e)e[f].process(a,c);b.isFunction(this.__setDefaults)&&this.__setDefaults()},getProcessors:function(){var a=this._processors;for(var c in a)b.isString(a[c])&&(a[c]=d(a[c]));return a},setProcessors:function(a){for(var b in a)this.setProcessor(type,b,a[b]);return this},hasProcessor:function(a){return a in this._processors},setProcessor:function(a,b){if(a in this._processors)throw new Error('Processor "'+a+'" is already exists!');return this._processors[a]=b,this},removeProcessor:function(a){if(!(a in this._processors))throw new Error('Processor "'+a+'" does not exists!');return delete this._processors[a],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},__construct:function(){for(var a in this)0===a.indexOf("__init")&&b.isFunction(this[a])&&this[a]();b.isFunction(this.init)&&this.init.apply(this,b.toArray(arguments)),b.isFunction(this.__setDefaults)&&this.__setDefaults(),b.isFunction(this.__clazz.__emitEvent)&&this.__clazz.__emitEvent("instance.created",this)}},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){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=b.toArray(arguments).slice(2),g={},h=0,i=d.length;i>h;++h)this.__collectValues(g,d[h],c||1,f);return g},__collectValues:function f(a,b,c,d,e){d=[].concat(d||[]);for(var g in b)d[0]&&g!==d[0]||(c>1&&"[object Object]"===Object.prototype.toString.call(b[g])?(g in a||(a[g]={}),f(a[g],b[g],c-1,d.slice(1))):!e&&g in a||(a[g]=b[g]));return a},__getMetaProcessors:function(){var a=this.__isClazz?this:this.__clazz;return this.__collectValues(a.__collectAllPropertyValues("__metaProcessors",1),d("Base").getProcessors())}}}),d("Constants",{process:function(a,b){this.applyConstants(a,b.constants||{})},applyConstants:function(a,b){a.__isInterfaceImplemented("constants")||a.__implementInterface("constants",this.interface),a.__initConstants();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=c[a[d]]}return c}}}),d("Events",{process:function(a,b){this.applyEvents(a,b.clazz_events||{}),this.applyEvents(a.prototype,b.events||{})},applyEvents:function(a,b){a.__isInterfaceImplemented("events")||a.__implementInterface("events",this.interface),a.__initEventsCallbacks();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(c,d){if(c in this.__events||(this.__events[c]={}),b.isUndefined(d)){var e=this.__getEventListeners(c);for(var d in e)this.__events[c][d]=a}else{if(!this.__hasEventListener(c,d))throw new Error('There is no "'+c+(d?'"::"'+d:"")+'" event callback!');this.__events[c][d]=a}return 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){var c=this.__collectAllPropertyValues.apply(this,["__events",2].concat(a||[]));for(var d in c)for(var e in c[d])b.isUndefined(c[d][e])&&delete c[d][e];return a?c[a]||{}:c}}}),d("Methods",{process:function(a,b){this.applyMethods(a,b.clazz_methods||{}),this.applyMethods(a.prototype,b.methods||{})},applyMethods: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){this.applyProperties(a,b.clazz_properties||{}),this.applyProperties(a.prototype,b.properties||{})},applyProperties:function(a,b){a.__isInterfaceImplemented("properties")||a.__implementInterface("properties",this.interface),a.__initProperties();var c=this.getPropertyMetaProcessor();for(var d in b)c.process(a,b[d],d)},getPropertyMetaProcessor:function(){var a=this._propertyMetaProcessor;return b.isString(a)&&(this._propertyMetaProcessor=d(a)),a},setPropertyMetaProcessor:function(a){return this._propertyMetaProcessor=a,this},"interface":{__initProperties:function(){this.__properties={},this.__setters={},this.__getters={}},__setDefaults:function(){var a=this.__getPropertiesParam();for(var c in a)if("default"in a[c]){var d=a[c].default;b.isFunction(d)&&(d=d.call(this)),this["_"+c]=d}},__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 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 in this},__getPropertyValue:function(a){b.isString(a)&&(a=a.split("."));var c=a.shift();if(!this.__hasProperty(c))throw new Error('Property "'+c+'" does not exists!');for(var d=this.__applyGetters(c,this["_"+c]),e=0,f=a.length;f>e;++e){var g=a[e];if(!(g in d))throw new Error('Property "'+[c].concat(a.slice(0,e+1)).join(".")+'" does not exists!');d=this.__applyGetters(c,d[g],a.slice(0,e+1))}return d},__hasPropertyValue:function(a){b.isString(a)&&(a=a.split("."));var c=a.shift();if(!this.__hasProperty(c))throw new Error('Property "'+c+'" does not exists!');for(var d=this.__applyGetters(c,this["_"+c]),e=0,f=a.length;f>e;++e){var g=a[e];if(!(g in d))return!1;d=this.__applyGetters(c,d[g],a.slice(0,e+1))}return!b.isUndefined(d)&&!b.isNull(d)},__isPropertyValue:function(a,c){var d=this.__getPropertyValue(a);return b.isUndefined(c)?!!d:d===c},__clearPropertyValue:function(c){b.isString(c)&&(c=c.split("."));var d=c.shift();if(!this.__hasProperty(d))throw new Error('Property "'+d+'" does not exists!');var e,f;if(c.length){if(e=b.last(c),f=this.__getPropertyValue([d].concat(c).slice(0,-1)),!(e in f))throw new Error('Property "'+[d].concat(c).join(".")+'" does not exists!')}else e="_"+d,f=this;var g=f[e];return f[e]=b.isSimpleObject(g)&&{}||b.isArray&&[]||a,this.__checkEmitEvent()&&this.__emitPropertyCleared([d].concat(c),g),this},__removePropertyValue:function(c){b.isString(c)&&(c=c.split("."));var d=c.shift();if(!this.__hasProperty(d))throw new Error('Property "'+d+'" does not exists!');var e,f;if(c.length){if(e=b.last(c),f=this.__getPropertyValue([d].concat(c).slice(0,-1)),!(e in f))throw new Error('Property "'+[d].concat(c).join(".")+'" does not exists!')}else e="_"+d,f=this;var g=f[e];return c.length?delete f[e]:f[e]=a,this.__checkEmitEvent()&&this.__emitPropertyRemoved([d].concat(c),g),this},__setPropertyValue:function(a,c){b.isString(a)&&(a=a.split("."));var d=a.shift();if(!this.__hasProperty(d))throw new Error('Property "'+d+'" does not exists!');var e,f;a.length?(e=b.last(a),f=this.__getPropertyValue([d].concat(a).slice(0,-1))):(e="_"+d,f=this);var g=e in f,h=f[e],i=this.__applySetters(d,c,a);return f[e]=i,this.__checkEmitEvent()&&this.__emitPropertySetted([d].concat(a),i,h,g),this},__emitPropertyRemoved:function(a,c){var d,e;return this.__checkEmitEvent(!0),b.isString(a)&&(a=a.split(".")),a.length&&(d=a.slice(0,-1).join("."),e=b.last(a),this.__emitEvent("property."+d+".item_removed",e,c),this.__emitEvent("property.item_removed",d,e,c)),d=a.join("."),this.__emitEvent("property."+d+".removed",c),this.__emitEvent("property.removed",d,c),this},__emitPropertyCleared:function(a,c){var d,e,f,g;if(this.__checkEmitEvent(!0),b.isString(a)&&(a=a.split(".")),b.isSimpleObject(c))for(e in c)this.__emitPropertyRemoved(a.concat(e),c[e]);else if(b.isArray(c))for(f=0,g=c.length;g>f;++f)this.__emitPropertyRemoved(a.concat(f),c[f]);return d=a.join("."),this.__emitEvent("property."+d+".cleared",c),this.__emitEvent("property.cleared",d,c),this},__emitPropertySetted:function(a,c,d,e){var f,g,h,i,j;this.__checkEmitEvent(!0),b.isString(a)&&(a=a.split("."));var k=!0;if(b.isSimpleObject(c)&&b.isSimpleObject(d)){for(h in d)if(c[h]!==d[h]){k=!1;break}}else if(b.isArray(c)&&b.isArray(d)){for(i=0,j=d.length;j>i;++i)if(c[i]!==d[i]){k=!1;break}}else c!==d&&(k=!1);return k||(f=a.join("."),g=b.isUndefined(d)||b.isNull(d)?"setted":"changed",this.__emitEvent("property."+f+"."+g,c,d),this.__emitEvent("property."+g,f,c,d),a.length&&!e&&(f=a.slice(0,-1).join("."),h=b.last(a),this.__emitEvent("property."+f+".item_added",h,c),this.__emitEvent("property.item_added",f,h,c))),this},__checkEmitEvent:function(a){a=b.isUndefined(a)?!1:a;var c=b.isFunction(this.__emitEvent);if(a&&!c)throw new Error("__emitEvent method does not realized!");return c},__addSetter:function(a,c,d,e){if(b.isUndefined(e)&&(e=d,d=0),b.isArray(e))d=e[0],e=e[1];else if(!b.isFunction(e))throw new Error("Setter callback must be a function!");return a in this.__setters||(this.__setters[a]={}),this.__setters[a][c]=[d,e],this},__getSetters:function(a,b){var c=this.__collectAllPropertyValues.apply(this,["__setters",1].concat(a||[]));if(!a)return c;if(c=c[a],!b)return c[a];var d=[];for(var e in c)d.push(c[e]);d=d.sort(function(a,b){return b[0]-a[1]});for(var f=0,g=d.length;g>f;++f)d[f]=d[f][1];return d},__applySetters:function(a,c,d){d=d||[];for(var e=this.__getSetters(a,!0),f=0,g=e.length;g>f;++f){var h=e[f].call(this,c,d);b.isUndefined(h)||(c=h)}return c},__addGetter:function(a,c,d,e){if(b.isUndefined(e)&&(e=d,d=0),b.isArray(e))d=e[0],e=e[1];else if(!b.isFunction(e))throw new Error("Getter callback must be a function!");return a in this.__getters||(this.__getters[a]={}),this.__getters[a][c]=[d,e],this},__getGetters:function(a,b){var c=this.__collectAllPropertyValues.apply(this,["__getters",1].concat(a||[]));if(!a)return c;if(c=c[a],!b)return c[a];var d=[];for(var e in c)d.push(c[e]);d=d.sort(function(a,b){return b[0]-a[1]});for(var f=0,g=d.length;g>f;++f)d[f]=d[f][1];return d},__applyGetters:function(a,c,d){d=d||[];for(var e=this.__getGetters(a,!0),f=0,g=e.length;g>f;++f){var h=e[f].call(this,c,d);b.isUndefined(h)||(c=h)}return c},__setData:function(a){for(var b in a)this.__hasProperty(b)&&this.__setPropertyValue(b,a[b]);return this},__getData:function(){var a={},c=this.__getPropertiesParam();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&&b.isSimpleObject(e[1])?{type:e}:{type:[e[0],e[2]||{}],"default":e[1]}:b.isSimpleObject(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",methods:"Property/Methods",constraints:"Property/Constraints",converters:"Property/Converters",getters:"Property/Getters",setters:"Property/Setters"}}),e("Property","meta",function(c){c("Constraints",{SETTER_NAME:"__constraints__",SETTER_WEIGHT:-100,process:function(a,b,c){var d=this;a.__addSetter(c,this.SETTER_NAME,this.SETTER_WEIGHT,function(a,e){return d.apply(a,b,c,e,this)})},apply:function(a,b,c,d,e){for(var f in b)if(!b[f].call(e,a,c,d))throw new Error('Constraint "'+f+'" was failed!');return a}}),c("Converters",{SETTER_NAME:"__converters__",SETTER_WEIGHT:100,process:function(a,b,c){var d=this;a.__addSetter(c,this.SETTER_NAME,this.SETTER_WEIGHT,function(a,e){return d.apply(a,b,c,e,this)})},apply:function(a,b,c,d,e){for(var f in b)a=b[f].call(e,a,c,d);return a}}),c("Default",{process:function(a,c,d){b.isUndefined(c)||a.__setPropertyParam(d,"default",c)}}),c("Getters",{process:function(a,b,c){for(var d in b)a.__addGetter(c,d,b[d])}}),c("Methods",{process:function(a,b,c){for(var d=0,e=b.length;e>d;++d)this.addMethodToObject(b[d],a,c)},addMethodToObject:function(a,b,c){var d=this.createMethod(a,c);b[d.name]=d.body},createMethod:function(a,c){if(!(a in this._methods))throw new Error('Method "'+a+'" does not exists!');var d=this._methods[a](c);return b.isFunction(d)&&(d={name:this.getMethodName(c,a),body:d}),d},getMethodName:function(a,b){var c="";a=a.replace(/^(_+)/g,function(a){return c=a,""});var d="is"===b&&0===a.indexOf("is")?a:b+a[0].toUpperCase()+a.slice(1);return c+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(c){return this.__getPropertyValue([a].concat(b.isString(c)?c.split("."):c||[]))}},set:function(c){return function(d,e){return b.isUndefined(e)&&(e=d,d=a),this.__setPropertyValue([c].concat(b.isString(d)?d.split("."):d||[]),e)}},is:function(c){return function(d,e){return b.isUndefined(e)&&(e=d,d=a),this.__isPropertyValue([c].concat(b.isString(d)?d.split("."):d||[]),e)}},has:function(a){return function(c){return this.__hasPropertyValue([a].concat(b.isString(c)?c.split("."):c||[]))}},clear:function(a){return function(c){return this.__clearPropertyValue([a].concat(b.isString(c)?c.split("."):c||[]))}},remove:function(a){return function(c){return this.__removePropertyValue([a].concat(b.isString(c)?c.split("."):c||[]))}}}}),c("Setters",{process:function(a,b,c){for(var d in b)a.__addSetter(c,d,b[d])}}),c("Type",{SETTER_NAME:"__type__",SETTER_WEIGHT:-1e3,process:function(a,b,c){var d=this;a.__addSetter(c,this.SETTER_NAME,this.SETTER_WEIGHT,function(e,f){for(var g=b||{},h=0,i=f.length;i>h;++h){var j=g[1]||{};if(!("element"in j))return e;g=j.element}return d.apply(e,g,c,f,a)})},apply:function(a,c,d,e,f){if(b.isUndefined(a)||b.isNull(a))return a;var g={};if(b.isArray(c)&&(g=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,g,d,e,f)},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,e,f){if(b.isString(a)&&(a=a.split(c.delimiter||this._defaultArrayDelimiter)),"element"in c)for(var g=0,h=a.length;h>g;++g)a[g]=this.apply(a[g],c.element,d,e.concat(g),f);return a},hash:function(a,c,d,e,f){if(!b.isObject(a))throw new Error('Value of property "'+[d].concat(e).join(".")+'" must have object type!');if("keys"in c)for(var g in a)if(-1===c.keys.indexOf(g))throw new Error('Unsupported hash key "'+g+'" for property "'+[d].concat(e).join(".")+'"!');if("element"in c)for(var g in a)a[g]=this.apply.call(this,a[g],c.element,d,e.concat(g),f);return a},object:function(a,c,d,e,f){if(!b.isObject(a))throw new Error('Value of property "'+d+'" must have an object type!');if("instanceOf"in c){var g=c.instanceOf,h=f.__isClazz?f.__clazz:f.__clazz.__clazz;if(b.isString(g)&&(g=h.getNamespace().adjustPath(g),a.__clazz||(g=h(g))),a.__clazz?!a.__clazz.__isSubclazzOf(g):!(a instanceof g)){var i=g.__isClazz?g.__name:b.isString(g)?g:"another";throw new Error('Value of property "'+d+'" must be instance of '+i+" 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(){return b.construct(this,b.toArray(arguments))},parent:function(a,c,d){a=a||this;var e=a.__isClazz?this.__parent:this.__parent.prototype;if(!c)return e;if(!(c in e))throw new Error('Parent does not have property "'+c+'"!');return b.isFunction(e[c])?e[c].apply(a,d||[]):e[c]},emit:function(){return this.__emitEvent.apply(this,b.toArray(arguments))},on:function(a,b,c){return this.__addEventListener(a,b,c)},off:function(a,b){return this.__removeEventListener(a,b)},"const":function(){return this.__getConstant.apply(this,b.toArray(arguments))}},methods:{getUID:function(){return this.__uid},init:function(b){return this.__uid=++a,this.__setData(b)},emit:function(){return this.__emitEvent.apply(this,b.toArray(arguments))},on:function(a,b,c){return this.__addEventListener(a,b,c)},off:function(a,b){return this.__removeEventListener(a,b)},"const":function(){return this.__clazz.const.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}}); | ||
!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.isSimpleObject=function(a){return a&&{}.constructor===a.constructor},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.clone=function(b){return a.isObject(b)?a.isArray(b)?b.slice():a.extend({},b):b},a.last=function(a){return a[a.length-1]},a.construct=function(a,b){var c=function(){return a.apply(this,b)};return c.prototype=a.prototype,new c},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}),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;return this instanceof a?(b.isFunction(a.__construct)&&(c=a.__construct.apply(this,b.toArray(arguments))),b.isUndefined(c)?void 0:c):b.construct(a,b.toArray(arguments))}},applyParent:function(c,d){if(d=d||this.getBaseClazz())for(var e in d)e in c||(b.isFunction(d[e])?c[e]=d[e]:"_"===e[0]&&(c[e]=a));return c.prototype=b.extend(Object.create(d?d.prototype:{}),c.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",{_processors:{constants:"Constants",properties:"Properties",methods:"Methods",events:"Events"},process:function(a,c){a.__isClazz||b.extend(a,this.clazz_interface),a.__interfaces||(a.__interfaces=[],a.prototype.__interfaces=[],b.extend(a,this.common_interface),b.extend(a.prototype,this.common_interface)),a.__metaProcessors=c.meta_processors||{};var d=c.parent;if(d&&!a.__isSubclazzOf(d))throw new Error('Clazz "'+a.__name+'" must be subclazz of "'+d.__isClazz?d.__name:d+'"!');var e=a.__getMetaProcessors();for(var f in e)e[f].process(a,c);b.isFunction(a.__setDefaults)&&a.__setDefaults()},getProcessors:function(){var a=this._processors;for(var c in a)b.isString(a[c])&&(a[c]=d(a[c]));return a},setProcessors:function(a){for(var b in a)this.setProcessor(type,b,a[b]);return this},hasProcessor:function(a){return a in this._processors},setProcessor:function(a,b){if(a in this._processors)throw new Error('Processor "'+a+'" is already exists!');return this._processors[a]=b,this},removeProcessor:function(a){if(!(a in this._processors))throw new Error('Processor "'+a+'" does not exists!');return delete this._processors[a],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},__construct:function(){for(var a in this)0===a.indexOf("__init")&&b.isFunction(this[a])&&this[a]();b.isFunction(this.init)&&this.init.apply(this,b.toArray(arguments)),b.isFunction(this.__setDefaults)&&this.__setDefaults(),b.isFunction(this.__clazz.__emitEvent)&&this.__clazz.__emitEvent("instance.created",this)}},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},__collectAllPropertyValue:function(a){if(this.hasOwnProperty(a)&&!b.isUndefined(this[a]))return this[a];if(this.__proto&&this.__proto.hasOwnProperty(a)&&!b.isUndefined(this.__proto[a]))return this.__proto[a];for(var c=this.__parent;c;){if(c.hasOwnProperty(a)&&!b.isUndefined(c[a]))return c[a];c=c.__parent}},__collectAllPropertyValues:function(a,c){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=b.toArray(arguments).slice(2),g={},h=0,i=d.length;i>h;++h)this.__collectValues(g,d[h],c||1,f);return g},__collectValues:function f(a,c,d,e,g){e=[].concat(e||[]);for(var h in c)e[0]&&h!==e[0]||(d>1&&b.isSimpleObject(c[h])?(h in a||(a[h]={}),f(a[h],c[h],d-1,e.slice(1))):!g&&h in a||(a[h]=c[h]));return a},__getMetaProcessors:function(){var a=this.__isClazz?this:this.__clazz;return this.__collectValues(a.__collectAllPropertyValues("__metaProcessors",1),d("Base").getProcessors())}}}),d("Constants",{process:function(a,b){this.applyConstants(a,b.constants||{})},applyConstants:function(a,b){a.__isInterfaceImplemented("constants")||a.__implementInterface("constants",this.interface),a.__initConstants();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=c[a[d]]}return c}}}),d("Events",{process:function(a,b){this.applyEvents(a,b.clazz_events||{}),this.applyEvents(a.prototype,b.events||{})},applyEvents:function(a,b){a.__isInterfaceImplemented("events")||a.__implementInterface("events",this.interface),a.__initEventsCallbacks();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(c,d){if(c in this.__events||(this.__events[c]={}),b.isUndefined(d)){var e=this.__getEventListeners(c);for(var d in e)this.__events[c][d]=a}else{if(!this.__hasEventListener(c,d))throw new Error('There is no "'+c+(d?'"::"'+d:"")+'" event callback!');this.__events[c][d]=a}return 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){var c=this.__collectAllPropertyValues.apply(this,["__events",2].concat(a||[]));for(var d in c)for(var e in c[d])b.isUndefined(c[d][e])&&delete c[d][e];return a?c[a]||{}:c}}}),d("Methods",{process:function(a,b){this.applyMethods(a,b.clazz_methods||{}),this.applyMethods(a.prototype,b.methods||{})},applyMethods: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){this.applyProperties(a,b.clazz_properties||{}),this.applyProperties(a.prototype,b.properties||{})},applyProperties:function(a,b){a.__isInterfaceImplemented("properties")||a.__implementInterface("properties",this.interface),a.__initProperties();var c=this.getPropertyMetaProcessor();for(var d in b)c.process(a,b[d],d)},getPropertyMetaProcessor:function(){var a=this._propertyMetaProcessor;return b.isString(a)&&(this._propertyMetaProcessor=d(a)),a},setPropertyMetaProcessor:function(a){return this._propertyMetaProcessor=a,this},"interface":{__initProperties:function(){this.__properties={},this.__setters={},this.__getters={}},__setDefaults:function(){var a=this.__getPropertiesParam();for(var c in a){var d=this.__getPropertyValue(c);if(b.isUndefined(d)&&"default"in a[c]){var e=a[c].default;b.isFunction(e)&&(e=e.call(this)),e&&({}.constructor===e.constructor||b.isArray(e))&&(e=b.clone(e)),this.__setPropertyValue(c,e)}}},__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 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||[]))[a];return b?c[b]:c},__hasProperty:function(a){return"_"+a in this},__getPropertyValue:function(a){b.isString(a)&&(a=a.split("."));var c=a.shift();if(!this.__hasProperty(c))throw new Error('Property "'+c+'" does not exists!');for(var d=this.__applyGetters(c,this["_"+c]),e=0,f=a.length;f>e;++e){var g=a[e];if(!(g in d))throw new Error('Property "'+[c].concat(a.slice(0,e+1)).join(".")+'" does not exists!');d=this.__applyGetters(c,d[g],a.slice(0,e+1))}if(this.__checkEmitEvent()){var h=[c].concat(a).join(".");this.__emitEvent("property."+h+".get",d),this.__emitEvent("property.get",h,d)}return d},__hasPropertyValue:function(a){b.isString(a)&&(a=a.split("."));var c=a.shift();if(!this.__hasProperty(c))throw new Error('Property "'+c+'" does not exists!');for(var d=null,e=this.__applyGetters(c,this["_"+c]),f=0,g=a.length;g>f;++f){var h=a[f];if(!(h in e)){d=!1;break}e=this.__applyGetters(c,e[h],a.slice(0,f+1))}if(b.isNull(d))var d=!b.isUndefined(e)&&!b.isNull(e);if(this.__checkEmitEvent()){var i=[c].concat(a).join(".");this.__emitEvent("property."+i+".has",d),this.__emitEvent("property.has",i,d)}return d},__isPropertyValue:function(a,c){var d=this.__getPropertyValue(a),e=b.isUndefined(c)?!!d:d===c;return this.__checkEmitEvent()&&(this.__emitEvent("property."+a+".is",e),this.__emitEvent("property.is",a,e)),e},__clearPropertyValue:function(c){b.isString(c)&&(c=c.split("."));var d=c.shift();if(!this.__hasProperty(d))throw new Error('Property "'+d+'" does not exists!');var e,f;if(c.length){if(e=b.last(c),f=this.__getPropertyValue([d].concat(c).slice(0,-1)),!(e in f))throw new Error('Property "'+[d].concat(c).join(".")+'" does not exists!')}else e="_"+d,f=this;var g=f[e],h=b.isSimpleObject(g)&&{}||b.isArray(g)&&[]||a;return f[e]=h,this.__checkEmitEvent()&&this.__emitPropertyClear([d].concat(c),g,h),this},__removePropertyValue:function(c){b.isString(c)&&(c=c.split("."));var d=c.shift();if(!this.__hasProperty(d))throw new Error('Property "'+d+'" does not exists!');var e,f;if(c.length){if(e=b.last(c),f=this.__getPropertyValue([d].concat(c).slice(0,-1)),!(e in f))return this}else e="_"+d,f=this;var g=f[e];return c.length?delete f[e]:f[e]=a,this.__checkEmitEvent()&&this.__emitPropertyRemove([d].concat(c),g),this},__setPropertyValue:function(a,c){b.isString(a)&&(a=a.split("."));var d=a.shift();if(!this.__hasProperty(d))throw new Error('Property "'+d+'" does not exists!');var e,f;a.length?(e=b.last(a),f=this.__getPropertyValue([d].concat(a).slice(0,-1))):(e="_"+d,f=this);var g=e in f,h=f[e],i=this.__applySetters(d,c,a);return f[e]=i,this.__checkEmitEvent()&&this.__emitPropertySet([d].concat(a),i,h,g),this},__emitPropertyRemove:function(a,c){var d,e;return this.__checkEmitEvent(!0),b.isString(a)&&(a=a.split(".")),a.length&&(d=a.slice(0,-1).join("."),e=b.last(a),this.__emitEvent("property."+d+".item_removed",e,c),this.__emitEvent("property.item_removed",d,e,c)),d=a.join("."),this.__emitEvent("property."+d+".remove",c),this.__emitEvent("property.remove",d,c),this},__emitPropertyClear:function(a,c){var d,e,f,g;if(this.__checkEmitEvent(!0),b.isString(a)&&(a=a.split(".")),b.isSimpleObject(c))for(e in c)this.__emitPropertyRemove(a.concat(e),c[e]);else if(b.isArray(c))for(f=0,g=c.length;g>f;++f)this.__emitPropertyRemove(a.concat(f),c[f]);return d=a.join("."),this.__emitEvent("property."+d+".clear",c),this.__emitEvent("property.clear",d,c),this},__emitPropertySet:function(a,c,d,e){var f,g,h,i,j;this.__checkEmitEvent(!0),b.isString(a)&&(a=a.split("."));var k=!0;if(b.isSimpleObject(c)&&b.isSimpleObject(d)){for(h in d)if(c[h]!==d[h]){k=!1;break}}else if(b.isArray(c)&&b.isArray(d)){for(i=0,j=d.length;j>i;++i)if(c[i]!==d[i]){k=!1;break}}else c!==d&&(k=!1);return k||(f=a.join("."),this.__emitEvent("property."+f+".set",c,d),this.__emitEvent("property.set",f,c,d),a.length&&!e&&(f=a.slice(0,-1).join("."),h=b.last(a),this.__emitEvent("property."+f+".item_added",h,c),this.__emitEvent("property.item_added",f,h,c))),this},__checkEmitEvent:function(a){a=b.isUndefined(a)?!1:a;var c=b.isFunction(this.__emitEvent);if(a&&!c)throw new Error("__emitEvent method does not realized!");return c},__addSetter:function(a,c,d,e){if(b.isUndefined(e)&&(e=d,d=0),b.isArray(e))d=e[0],e=e[1];else if(!b.isFunction(e))throw new Error("Setter callback must be a function!");return a in this.__setters||(this.__setters[a]={}),this.__setters[a][c]=[d,e],this},__getSetters:function(a,b){var c=this.__collectAllPropertyValues.apply(this,["__setters",1].concat(a||[]));if(!a)return c;if(c=c[a],!b)return c[a];var d=[];for(var e in c)d.push(c[e]);d=d.sort(function(a,b){return b[0]-a[0]});for(var f=0,g=d.length;g>f;++f)d[f]=d[f][1];return d},__applySetters:function(a,c,d){d=d||[];for(var e=this.__getSetters(a,!0),f=0,g=e.length;g>f;++f){var h=e[f].call(this,c,d);b.isUndefined(h)||(c=h)}return c},__addGetter:function(a,c,d,e){if(b.isUndefined(e)&&(e=d,d=0),b.isArray(e))d=e[0],e=e[1];else if(!b.isFunction(e))throw new Error("Getter callback must be a function!");return a in this.__getters||(this.__getters[a]={}),this.__getters[a][c]=[d,e],this},__getGetters:function(a,b){var c=this.__collectAllPropertyValues.apply(this,["__getters",1].concat(a||[]));if(!a)return c;if(c=c[a],!b)return c[a];var d=[];for(var e in c)d.push(c[e]);d=d.sort(function(a,b){return b[0]-a[0]});for(var f=0,g=d.length;g>f;++f)d[f]=d[f][1];return d},__applyGetters:function(a,c,d){d=d||[];for(var e=this.__getGetters(a,!0),f=0,g=e.length;g>f;++f){var h=e[f].call(this,c,d);b.isUndefined(h)||(c=h)}return c},__setData:function(a){for(var c in a)if(this.__hasProperty(c.split(".")[0])){var d=a[c];b.isNull(d)?this.__removePropertyValue(c):this.__setPropertyValue(c,d)}return this},__getData:function(){var a={},b=this.__getPropertiesParam();for(var c in b)a[c]=this.__processData(this.__getPropertyValue(c));return a},__processData:function g(a,c){if(!a)return a;var d,e,f;if(a.constructor==={}.constructor)for(f in a)b.isUndefined(a[f])?delete a[f]:a[f]=g(a[f],c);else if(b.isArray(a))for(d=0,e=a.length;e>d;++d)b.isUndefined(a[d])?(--d,--e):a[d]=g(a[d],c);else{c=b.extend({},c,{__getData:null});for(var h in c)if(b.isFunction(a[h])){var i=c[h];(b.isNull(i)||b.isUndefined(i))&&(i=[]),b.isArray(i)||(i=[i]),a=a[h].apply(a,i)}}return a}}}),d("Property",{process:function(c,e,f){c["_"+f]=a,b.isArray(e)?e=3!==e.length&&b.isSimpleObject(e[1])?{type:e}:{type:[e[0],e[2]||{}],"default":e[1]}:b.isSimpleObject(e)||(e={"default":e}),"methods"in e||(e.methods=["get","set","has","is","clear","remove"]),c.__setPropertyParam(f,{});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",methods:"Property/Methods",constraints:"Property/Constraints",converters:"Property/Converters",getters:"Property/Getters",setters:"Property/Setters"}}),e("Property","meta",function(c){c("Constraints",{SETTER_NAME:"__constraints__",SETTER_WEIGHT:-100,process:function(a,b,c){var d=this;a.__addSetter(c,this.SETTER_NAME,this.SETTER_WEIGHT,function(a,e){return d.apply(a,b,c,e,this)})},apply:function(a,b,c,d,e){for(var f in b)if(!b[f].call(e,a,d,c))throw new Error('Constraint "'+f+'" was failed!');return a}}),c("Converters",{SETTER_NAME:"__converters__",SETTER_WEIGHT:100,process:function(a,b,c){var d=this;a.__addSetter(c,this.SETTER_NAME,this.SETTER_WEIGHT,function(a,e){return d.apply(a,b,c,e,this)})},apply:function(a,b,c,d,e){for(var f in b)a=b[f].call(e,a,d,c);return a}}),c("Default",{process:function(a,c,d){b.isUndefined(c)||a.__setPropertyParam(d,"default",c)}}),c("Getters",{process:function(a,b,c){for(var d in b)a.__addGetter(c,d,b[d])}}),c("Methods",{process:function(a,b,c){for(var d=0,e=b.length;e>d;++d)this.addMethodToObject(b[d],a,c)},addMethodToObject:function(a,b,c){var d=this.createMethod(a,c);b[d.name]=d.body},createMethod:function(a,c){if(!(a in this._methods))throw new Error('Method "'+a+'" does not exists!');var d=this._methods[a](c);return b.isFunction(d)&&(d={name:this.getMethodName(c,a),body:d}),d},getMethodName:function(a,b){var c="";a=a.replace(/^(_+)/g,function(a){return c=a,""});var d="is"===b&&0===a.indexOf("is")?a:b+a[0].toUpperCase()+a.slice(1);return c+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(c){return this.__getPropertyValue([a].concat(b.isString(c)?c.split("."):c||[]))}},set:function(c){return function(d,e){return b.isUndefined(e)&&(e=d,d=a),this.__setPropertyValue([c].concat(b.isString(d)?d.split("."):d||[]),e)}},is:function(c){return function(d,e){return b.isUndefined(e)&&(e=d,d=a),this.__isPropertyValue([c].concat(b.isString(d)?d.split("."):d||[]),e)}},has:function(a){return function(c){return this.__hasPropertyValue([a].concat(b.isString(c)?c.split("."):c||[]))}},clear:function(a){return function(c){return this.__clearPropertyValue([a].concat(b.isString(c)?c.split("."):c||[]))}},remove:function(a){return function(c){return this.__removePropertyValue([a].concat(b.isString(c)?c.split("."):c||[]))}}}}),c("Setters",{process:function(a,b,c){for(var d in b)a.__addSetter(c,d,b[d])}}),c("Type",{SETTER_NAME:"__type__",SETTER_WEIGHT:-1e3,process:function(a,b,c){var d=this;a.__addSetter(c,this.SETTER_NAME,this.SETTER_WEIGHT,function(e,f){for(var g=b||{},h=0,i=f.length;i>h;++h){var j=g[1]||{};if(!("element"in j))return e;g=j.element}return d.apply(e,g,c,f,a)})},apply:function(a,c,d,e,f){if(b.isUndefined(a)||b.isNull(a))return a;var g={};if(b.isArray(c)&&(g=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,g,d,e,f)},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,e,f){if(b.isString(a)&&(a=a.split(c.delimiter||this._defaultArrayDelimiter)),"element"in c)for(var g=0,h=a.length;h>g;++g)a[g]=this.apply(a[g],c.element,d,e.concat(g),f);return a},hash:function(a,c,d,e,f){if(!b.isObject(a))throw new Error('Value of property "'+[d].concat(e).join(".")+'" must have object type!');if("keys"in c)for(var g in a)if(-1===c.keys.indexOf(g))throw new Error('Unsupported hash key "'+g+'" for property "'+[d].concat(e).join(".")+'"!');if("element"in c)for(var g in a)a[g]=this.apply.call(this,a[g],c.element,d,e.concat(g),f);return a},object:function(a,c,d,e,f){if(!b.isObject(a))throw new Error('Value of property "'+d+'" must have an object type!');if("instanceOf"in c){var g=c.instanceOf,h=f.__isClazz?f.__clazz:f.__clazz.__clazz;if(b.isString(g)&&(g=h.getNamespace().adjustPath(g),a.__clazz||(g=h(g))),a.__clazz?!a.__clazz.__isSubclazzOf(g):!(a instanceof g)){var i=g.__isClazz?g.__name:b.isString(g)?g:"another";throw new Error('Value of property "'+d+'" must be instance of '+i+" 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(){return b.construct(this,b.toArray(arguments))},parent:function(a,c,d){a=a||this;var e=a.__isClazz?this.__parent:this.__parent.prototype;if(!c)return e;if(!(c in e))throw new Error('Parent does not have property "'+c+'"!');return b.isFunction(e[c])?e[c].apply(a,d||[]):e[c]},emit:function(){return this.__emitEvent.apply(this,b.toArray(arguments))},on:function(a,b,c){return this.__addEventListener(a,b,c)},off:function(a,b){return this.__removeEventListener(a,b)},"const":function(){return this.__getConstant.apply(this,b.toArray(arguments))}},methods:{getUID:function(){return this.__uid},init:function(b){return this.__uid=++a,this.__setData(b)},emit:function(){return this.__emitEvent.apply(this,b.toArray(arguments))},on:function(a,b,c){return this.__addEventListener(a,b,c)},off:function(a,b){return this.__removeEventListener(a,b)},"const":function(){return this.__clazz.const.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 |
@@ -116,3 +116,3 @@ Clazz declaration | ||
* **name** - *clazz name*. Types: string. Required. | ||
* **name** - *clazz name*. Type: string. Required. | ||
@@ -128,3 +128,3 @@ It can be namespaced clazz name. | ||
* **parent** - *parent clazz*. Types: string, constructor function. Optional. | ||
* **parent** - *parent clazz*. Type: string, constructor function. Optional. | ||
@@ -131,0 +131,0 @@ Examples: |
@@ -23,18 +23,26 @@ Events | ||
**Instance events**: | ||
* **property.setted** - setting value of any property (property didn't have value before). | ||
Listener: `function(propertyName, value) { ... }`; | ||
* **property.{propertyName}.setted** - setting value of concrete property. | ||
Listener: `function(newValue, oldValue) { ... }`; | ||
* **property.changed** - changing value of any property. | ||
* **property.get** - getting value for any property | ||
Listener: `function(propertyName, value)`; | ||
* **property.{propertyName}.get** - getting value for concrete property | ||
Listener: `function(value)`; | ||
* **property.has** - 'has' check for any property | ||
Listener: `function(propertyName, hasResult)`; | ||
* **property.{propertyName}.has** - 'has' check for concrete property | ||
Listener: `function(hasResult)`; | ||
* **property.is** - 'is' check for any property | ||
Listener: `function(propertyName, isResult)`; | ||
* **property.{propertyName}.is** - 'is' check for concrete property | ||
Listener: `function(isResult)`; | ||
* **property.set** - setting value for any property | ||
Listener: `function(propertyName, newValue, oldValue) { ... }`; | ||
* **property.{propertyName}.changed** - changing value of concrete property. | ||
* **property.{propertyName}.set** - setting value for concrete property. | ||
Listener: `function(newValue, oldValue) { ... }`; | ||
* **property.removed** - removing value of any property. | ||
* **property.remove** - removing value for any property. | ||
Listener: `function(propertyName, oldValue) { ... }`; | ||
* **property.{propertyName}.removed** - removing value of concrete property. | ||
* **property.{propertyName}.remove** - removing value for concrete property | ||
Listener: `function(oldValue) { ... }`; | ||
* **property.cleared** - clearing value of any property. | ||
Listener: `function(propertyName, oldValue) { ... }`; | ||
* **property.{propertyName}.cleared** - clearing value of concrete property. | ||
Listener: `function(oldValue) { ... }` | ||
* **property.clear** - clearing value for any property | ||
Listener: `function(propertyName, oldValue, newValue) { ... }`; | ||
* **property.{propertyName}.clear** - clearing value for concrete property | ||
Listener: `function(oldValue, newValue) { ... }` | ||
@@ -93,13 +101,12 @@ You can attach/detach cevent listeners to/from created clazz or clazz instances. Use `on`/`off` methods for this purposed. Their signatures: | ||
events: { | ||
"property.setted": { | ||
birthdaySetted: function(property, value) { | ||
"property.set": { | ||
birthdayChanged: function(property, newValue, oldValue) { | ||
if ('birthday' === property) { | ||
document.write( | ||
'Person "' + this.getUID() + '" ' + | ||
'set his birthday to "' + value + '"!<br>' | ||
'change his birthday form "' + oldValue + '" ' + | ||
'to "' + newValue + '"!<br>' | ||
) | ||
} | ||
} | ||
}, | ||
"property.changed": { | ||
}, | ||
addressChanged: function(property, newValue, oldValue) { | ||
@@ -114,13 +121,4 @@ if ('address' === property) { | ||
}, | ||
birthdayChanged: function(property, newValue, oldValue) { | ||
if ('birthday' === property) { | ||
document.write( | ||
'Person "'+this.getUID()+'" '+ | ||
'change his birthday from" '+oldValue+'" '+ | ||
'to "' + newValue + '"!<br>' | ||
); | ||
} | ||
} | ||
}, | ||
"property.address.removed": { | ||
"property.address.remove": { | ||
addressRemoved: function(oldAddress) { | ||
@@ -151,3 +149,3 @@ document.write( | ||
john.on("property.name.changed", 'nameChanged', function(newName, oldName) { | ||
john.on("property.name.set", 'nameChanged', function(newName, oldName) { | ||
document.write( | ||
@@ -161,3 +159,3 @@ 'Person "'+this.getUID()+'" '+ | ||
john.off('property.changed', 'birthdayChanged'); | ||
john.off('property.set', 'birthdayChanged'); | ||
john.setBirthday('1970-06-08'); | ||
@@ -164,0 +162,0 @@ |
@@ -10,3 +10,3 @@ clazz('Person', { | ||
cryToAll: function(crying) { | ||
document.write('Crying to all: "' + crying + '"!<br>'); | ||
document.write('Crying to all: "' + crying + '"!'); | ||
this.emit('crying', crying); | ||
@@ -42,13 +42,12 @@ } | ||
events: { | ||
"property.setted": { | ||
birthdaySetted: function(property, value) { | ||
"property.set": { | ||
birthdayChanged: function(property, newValue, oldValue) { | ||
if ('birthday' === property) { | ||
document.write( | ||
'Person "' + this.getUID() + '" ' + | ||
'set his birthday to "' + value + '"!<br>' | ||
'change his birthday form "' + oldValue + '" ' + | ||
'to "' + newValue + '"!<br>' | ||
) | ||
} | ||
} | ||
}, | ||
"property.changed": { | ||
}, | ||
addressChanged: function(property, newValue, oldValue) { | ||
@@ -58,18 +57,9 @@ if ('address' === property) { | ||
'Person "' + this.getUID() + '" ' + | ||
'change his address from " ' + oldValue + '" '+ | ||
'to "' + newValue + '"!<br>' | ||
'change his address from " ' + oldValue + '" '+ | ||
'to "' + newValue + '"!<br>' | ||
) | ||
} | ||
}, | ||
birthdayChanged: function(property, newValue, oldValue) { | ||
if ('birthday' === property) { | ||
document.write( | ||
'Person "'+this.getUID()+'" '+ | ||
'change his birthday from" '+oldValue+'" '+ | ||
'to "' + newValue + '"!<br>' | ||
); | ||
} | ||
} | ||
}, | ||
"property.address.removed": { | ||
"property.address.remove": { | ||
addressRemoved: function(oldAddress) { | ||
@@ -76,0 +66,0 @@ document.write( |
@@ -19,2 +19,3 @@ clazz('Person', { | ||
}, | ||
isIntelligent: ['boolean', true], | ||
birthday: ['datetime'], | ||
@@ -21,0 +22,0 @@ phone: ['string', { pattern: /\d{1,2}-\d{3}-\d{5,7}/ }], |
@@ -19,6 +19,7 @@ var Person = clazz('Person'); | ||
document.write('<b>Person instance "George":</b><br>' + | ||
'name: ' + person.getName() + '<br>' + | ||
'birth year: ' + person.getBirthday().getFullYear() + '<br>' + | ||
'address: ' + person.getAddress() + '<br>' + | ||
'sex: ' + person.getSex() + '<br>' | ||
'name: ' + person.getName() + '<br>' + | ||
'birth year: ' + person.getBirthday().getFullYear() + '<br>' + | ||
'address: ' + person.getAddress() + '<br>' + | ||
'sex: ' + person.getSex() + '<br>' + | ||
'isIntelligent: ' + person.isIntelligent() + '<br>' | ||
); |
{ | ||
"name": "clazz-js", | ||
"title": "ClazzJS", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "Portable JavaScript library for class-style OOP programming", | ||
@@ -25,8 +25,8 @@ "author": { | ||
"devDependencies": { | ||
"grunt": "~0.4.1", | ||
"grunt": "~0.4.2", | ||
"grunt-contrib-concat": "~0.3.0", | ||
"grunt-contrib-uglify": "~0.2.4", | ||
"grunt-jsbeautifier": "~0.2.3" | ||
"grunt-contrib-uglify": "~0.2.7", | ||
"grunt-jsbeautifier": "~0.2.6" | ||
}, | ||
"readmeFilename": "README.md" | ||
} |
ClazzJS | ||
======= | ||
ClazzJS is portable JavaScript library for class-style OOP programming. Its main goal to provide expressive DSL to | ||
ClazzJS is portable JavaScript library for class-style OOP programming. Its main goal is to provide expressive DSL to | ||
write your JavaScript programs in easy-to-understand, well-known, convenient and flexible class base manner. It's works | ||
@@ -15,2 +15,3 @@ well both on client and server sides. | ||
* Namespaces | ||
and more... | ||
@@ -22,3 +23,3 @@ You'll find the example bellow to have a common idea what I'm talking about. | ||
> This docs doesn't describe most features of the library, but not all. Use source to learn ClazzJS better. In every doc chapter there are links on respective source files. | ||
> This docs describe many features of the library, but not all. Use source to learn ClazzJS better. In every doc chapter there are links on respective source files. | ||
@@ -25,0 +26,0 @@ 1. [Installation](https://github.com/alexpods/ClazzJS/blob/master/docs/1.installation.md) |
@@ -16,3 +16,3 @@ var _ = (function() { | ||
_.isSimpleObject = function(obj) { | ||
return toString.call(obj) === '[object Object]'; | ||
return obj && ({}).constructor === obj.constructor; | ||
}; | ||
@@ -53,2 +53,7 @@ | ||
_.clone = function(obj) { | ||
if (!_.isObject(obj)) return obj; | ||
return _.isArray(obj) ? obj.slice() : _.extend({}, obj); | ||
}; | ||
_.last = function(arr) { | ||
@@ -55,0 +60,0 @@ return arr[arr.length - 1]; |
@@ -40,4 +40,4 @@ meta('Base', { | ||
if (_.isFunction(this.__setDefaults)) { | ||
this.__setDefaults(); | ||
if (_.isFunction(clazz.__setDefaults)) { | ||
clazz.__setDefaults(); | ||
} | ||
@@ -138,2 +138,21 @@ }, | ||
__collectAllPropertyValue: function(property) { | ||
if (this.hasOwnProperty(property) && !_.isUndefined(this[property])) { | ||
return this[property]; | ||
} | ||
if (this.__proto && this.__proto.hasOwnProperty(property) && !_.isUndefined(this.__proto[property])) { | ||
return this.__proto[property]; | ||
} | ||
var parent = this.__parent; | ||
while (parent) { | ||
if (parent.hasOwnProperty(property) && !_.isUndefined(parent[property])) { | ||
return parent[property]; | ||
} | ||
parent = parent.__parent; | ||
} | ||
}, | ||
__collectAllPropertyValues: function(property, level /* fields */) { | ||
@@ -178,3 +197,3 @@ | ||
if (level > 1 && Object.prototype.toString.call(container[name]) === '[object Object]') { | ||
if (level > 1 && _.isSimpleObject(container[name])) { | ||
if (!(name in collector)) { | ||
@@ -181,0 +200,0 @@ collector[name] = {}; |
@@ -51,3 +51,5 @@ meta('Properties', { | ||
if ('default' in propertiesParams[property]) { | ||
var propertyValue = this.__getPropertyValue(property); | ||
if (_.isUndefined(propertyValue) && 'default' in propertiesParams[property]) { | ||
var defaultValue = propertiesParams[property].default; | ||
@@ -59,3 +61,9 @@ | ||
this['_' + property] = defaultValue; | ||
if (defaultValue) { | ||
if ((({}).constructor === defaultValue.constructor) || _.isArray(defaultValue)) { | ||
defaultValue = _.clone(defaultValue) | ||
} | ||
} | ||
this.__setPropertyValue(property, defaultValue); | ||
} | ||
@@ -96,3 +104,3 @@ } | ||
__getPropertyParam: function(property, param) { | ||
var params = this.__collectAllPropertyValues.apply(this, ['__properties', 2, property].concat(param || [])); | ||
var params = this.__collectAllPropertyValues.apply(this, ['__properties', 2, property].concat(param || []))[property]; | ||
return param ? params[param] : params; | ||
@@ -130,2 +138,10 @@ }, | ||
if (this.__checkEmitEvent()) { | ||
var prop = [property].concat(fields).join('.'); | ||
this.__emitEvent('property.' + prop + '.get', value); | ||
this.__emitEvent('property.get', prop, value); | ||
} | ||
return value; | ||
@@ -146,3 +162,4 @@ }, | ||
var value = this.__applyGetters(property, this['_' + property]); | ||
var result = null; | ||
var value = this.__applyGetters(property, this['_' + property]); | ||
@@ -154,3 +171,4 @@ for (var i = 0, ii = fields.length; i < ii; ++i) { | ||
if (!(field in value)) { | ||
return false; | ||
result = false; | ||
break; | ||
} | ||
@@ -161,3 +179,14 @@ | ||
return !_.isUndefined(value) && !_.isNull(value); | ||
if (_.isNull(result)) { | ||
var result = !_.isUndefined(value) && !_.isNull(value); | ||
} | ||
if (this.__checkEmitEvent()) { | ||
var prop = [property].concat(fields).join('.'); | ||
this.__emitEvent('property.' + prop + '.has', result); | ||
this.__emitEvent('property.has', prop, result); | ||
} | ||
return result; | ||
}, | ||
@@ -167,4 +196,12 @@ | ||
__isPropertyValue: function(fields, compareValue) { | ||
var value = this.__getPropertyValue(fields); | ||
return !_.isUndefined(compareValue) ? value === compareValue : !!value; | ||
var value = this.__getPropertyValue(fields); | ||
var result = !_.isUndefined(compareValue) ? value === compareValue : !!value; | ||
if (this.__checkEmitEvent()) { | ||
this.__emitEvent('property.' + fields + '.is', result); | ||
this.__emitEvent('property.is', fields, result); | ||
} | ||
return result; | ||
}, | ||
@@ -200,6 +237,8 @@ | ||
container[field] = (_.isSimpleObject(oldValue) && {}) || (_.isArray && []) || undefined; | ||
var newValue = (_.isSimpleObject(oldValue) && {}) || (_.isArray(oldValue) && []) || undefined; | ||
container[field] = newValue; | ||
if (this.__checkEmitEvent()) { | ||
this.__emitPropertyCleared([property].concat(fields), oldValue); | ||
this.__emitPropertyClear([property].concat(fields), oldValue, newValue); | ||
} | ||
@@ -228,3 +267,3 @@ | ||
if (!(field in container)) { | ||
throw new Error('Property "' + [property].concat(fields).join('.') + '" does not exists!'); | ||
return this; | ||
} | ||
@@ -247,3 +286,3 @@ } | ||
if (this.__checkEmitEvent()) { | ||
this.__emitPropertyRemoved([property].concat(fields), oldValue); | ||
this.__emitPropertyRemove([property].concat(fields), oldValue); | ||
} | ||
@@ -282,3 +321,3 @@ return this; | ||
if (this.__checkEmitEvent()) { | ||
this.__emitPropertySetted([property].concat(fields), newValue, oldValue, wasExisted); | ||
this.__emitPropertySet([property].concat(fields), newValue, oldValue, wasExisted); | ||
} | ||
@@ -289,3 +328,3 @@ | ||
__emitPropertyRemoved: function(fields, oldValue) { | ||
__emitPropertyRemove: function(fields, oldValue) { | ||
var prop, key; | ||
@@ -309,4 +348,4 @@ | ||
this.__emitEvent('property.' + prop + '.removed', oldValue); | ||
this.__emitEvent('property.removed', prop, oldValue); | ||
this.__emitEvent('property.' + prop + '.remove', oldValue); | ||
this.__emitEvent('property.remove', prop, oldValue); | ||
@@ -316,3 +355,3 @@ return this; | ||
__emitPropertyCleared: function(fields, oldValue) { | ||
__emitPropertyClear: function(fields, oldValue) { | ||
var prop, key, i, ii; | ||
@@ -328,3 +367,3 @@ | ||
for (key in oldValue) { | ||
this.__emitPropertyRemoved(fields.concat(key), oldValue[key]); | ||
this.__emitPropertyRemove(fields.concat(key), oldValue[key]); | ||
} | ||
@@ -334,3 +373,3 @@ } | ||
for (i = 0, ii = oldValue.length; i < ii; ++i) { | ||
this.__emitPropertyRemoved(fields.concat(i), oldValue[i]); | ||
this.__emitPropertyRemove(fields.concat(i), oldValue[i]); | ||
} | ||
@@ -341,4 +380,4 @@ } | ||
this.__emitEvent('property.' + prop + '.cleared', oldValue); | ||
this.__emitEvent('property.cleared', prop, oldValue); | ||
this.__emitEvent('property.' + prop + '.clear', oldValue); | ||
this.__emitEvent('property.clear', prop, oldValue); | ||
@@ -348,3 +387,3 @@ return this; | ||
__emitPropertySetted: function(fields, newValue, oldValue, wasExists) { | ||
__emitPropertySet: function(fields, newValue, oldValue, wasExists) { | ||
var prop, event, key, i, ii; | ||
@@ -382,6 +421,5 @@ | ||
prop = fields.join('.'); | ||
event = _.isUndefined(oldValue) || _.isNull(oldValue) ? 'setted' : 'changed'; | ||
this.__emitEvent('property.' + prop + '.' + event, newValue, oldValue); | ||
this.__emitEvent('property.' + event, prop, newValue, oldValue); | ||
this.__emitEvent('property.' + prop + '.' + 'set', newValue, oldValue); | ||
this.__emitEvent('property.set', prop, newValue, oldValue); | ||
@@ -451,3 +489,3 @@ if (fields.length && !wasExists) { | ||
sortedSetters = sortedSetters.sort(function(s1, s2) { return s2[0] - s1[1]; }); | ||
sortedSetters = sortedSetters.sort(function(s1, s2) { return s2[0] - s1[0]; }); | ||
@@ -517,3 +555,3 @@ for (var i = 0, ii = sortedSetters.length; i < ii; ++i) { | ||
sortedGetters = sortedGetters.sort(function(s1, s2) { return s2[0] - s1[1]; }); | ||
sortedGetters = sortedGetters.sort(function(s1, s2) { return s2[0] - s1[0]; }); | ||
@@ -544,6 +582,9 @@ for (var i = 0, ii = sortedGetters.length; i < ii; ++i) { | ||
for (var property in data) { | ||
if (!this.__hasProperty(property)) { | ||
if (!this.__hasProperty(property.split('.')[0])) { | ||
continue; | ||
} | ||
this.__setPropertyValue(property, data[property]); | ||
var value = data[property]; | ||
_.isNull(value) ? this.__removePropertyValue(property) : this.__setPropertyValue(property, value); | ||
} | ||
@@ -559,22 +600,56 @@ return this; | ||
for (var property in properties) { | ||
var value = this.__getPropertyValue(property); | ||
data[property] = this.__processData(this.__getPropertyValue(property)); | ||
} | ||
if (_.isArray(value)) { | ||
for (var i = 0, ii = value.length; i < ii; ++i) { | ||
if (_.isFunction(value[i].__getData)) { | ||
value[i] = value[i].__getData(); | ||
} | ||
return data; | ||
}, | ||
__processData: function self_method(data, methods) { | ||
if (!data) { | ||
return data; | ||
} | ||
var i, ii, prop; | ||
if (data.constructor === ({}).constructor) { | ||
for (prop in data) { | ||
if (_.isUndefined(data[prop])) { | ||
delete data[prop]; | ||
continue; | ||
} | ||
data[prop] = self_method(data[prop], methods); | ||
} | ||
else if (value.constructor === {}.constructor) { | ||
for (var key in value) { | ||
if (_.isFunction(value[key].__getData)) { | ||
value[key] = value[key].__getData(); | ||
} | ||
} | ||
else if (_.isArray(data)) { | ||
for (i = 0, ii = data.length; i < ii; ++i) { | ||
if (_.isUndefined(data[i])) { | ||
--i; --ii; | ||
continue; | ||
} | ||
data[i] = self_method(data[i], methods); | ||
} | ||
else if (_.isFunction(value.__getData)) { | ||
value = value.__getData(); | ||
} | ||
else { | ||
methods = _.extend({}, methods, { __getData: null }); | ||
for (var method in methods) { | ||
if (!_.isFunction(data[method])) { | ||
continue; | ||
} | ||
var params = methods[method]; | ||
if (_.isNull(params) || _.isUndefined(params)) { | ||
params = []; | ||
} | ||
if (!_.isArray(params)) { | ||
params = [params]; | ||
} | ||
data = data[method].apply(data, params); | ||
} | ||
data[property] = value; | ||
} | ||
@@ -581,0 +656,0 @@ |
@@ -19,2 +19,4 @@ meta('Property', { | ||
object.__setPropertyParam(property, {}); | ||
for (var option in propertyMeta) { | ||
@@ -21,0 +23,0 @@ if (option in this._options) { |
@@ -17,3 +17,3 @@ meta('Constraints', { | ||
for (var name in constraints) { | ||
if (!constraints[name].call(object, value, property, fields)) { | ||
if (!constraints[name].call(object, value, fields, property)) { | ||
throw new Error('Constraint "' + name + '" was failed!'); | ||
@@ -20,0 +20,0 @@ } |
@@ -17,3 +17,3 @@ meta('Converters', { | ||
for (var name in converters) { | ||
value = converters[name].call(object, value, property, fields); | ||
value = converters[name].call(object, value, fields, property); | ||
} | ||
@@ -20,0 +20,0 @@ return value; |
Sorry, the diff of this file is too big to display
234439
3956
168