UNPKG

angular-property-binder

Version:

Bind property and keep safe the reference

6 lines 3.48 kB
// angular-property-binder // version: 0.1.12 // author: Gaignoux Nicolas // generated: Thu Apr 16 2015 19:20:53 GMT+0200 (Paris, Madrid (heure d’été)) // Autogenerated, do not edit. All changes will be undone. !function(a,b,angular){" use strict; ";angular.module("PropertyBinder",[]);var c=function(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")},d=function(){function a(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,d.key,d)}}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}();angular.module("PropertyBinder").provider("PropertyBinder.providers.binder",function(){this.$get=function(){var a=function(){function a(){var b=void 0===arguments[0]?[]:arguments[0];c(this,a),this._properties=b instanceof Array?b:[b],this._binded=!1,this._sealed=!1,this._to=void 0,this._from=void 0,this._path=[],this._aliases={},this._change=function(){}}return d(a,[{key:"from",value:function(a){var b=void 0===arguments[1]?[]:arguments[1];return this._throwErrorIfAlreadyBinded(),this._path="string"==typeof b?b=b.split("."):b,this._from=a,this}},{key:"to",value:function(a){return this._throwErrorIfAlreadyBinded(),this._to=a,this}},{key:"as",value:function(){var a=void 0===arguments[0]?{}:arguments[0];if(this._throwErrorIfAlreadyBinded(),a instanceof Object)if(a instanceof Array)for(var b=0;b<a.length;b++)this._properties[b]&&(this._aliases[this._properties[b]]=a[b]);else this._aliases=a;else if("string"==typeof a){if(1!==this._properties.length)throw Error("Ambiguous aliases");var c=a;this._aliases={},this._aliases[this._properties[0]]=c}return this}},{key:"onchange",value:function(){var a=void 0===arguments[0]?function(){}:arguments[0];return this._change=a,this}},{key:"seal",value:function(){return this._sealed=!0,this}},{key:"unseal",value:function(){return this._sealed=!1,this}},{key:"toggleSealing",value:function(){return this._sealed=!this._sealed,this}},{key:"apply",value:function(){if(this._throwErrorIfAlreadyBinded(),this._from&&this._to&&this._properties.length>0)for(var a=0;a<this._properties.length;a++)this._createProperty(this._properties[a]);return this._binded=!0,this}},{key:"destroy",value:function(){for(var a=0;a<this._properties.length;a++)this._deleteProperty(this._properties[a]);return this._binded=!1,this}},{key:"_deleteProperty",value:function(a){var b=this._aliases[a]||a;delete this._to[b]}},{key:"_createProperty",value:function(a){var b=this;Object.defineProperty(this._to,this._aliases[a]||a,{enumerable:!0,configurable:!0,get:function(){var c=b._getSrc();return c[a]instanceof Function?c[a].bind(c):c[a]},set:function(c){if(b._sealed)throw Error("Trying to update a sealed property");var d=b._getSrc(),e=d[a];d[a]=c,e!==c&&b._change(c,e)}})}},{key:"_getSrc",value:function(){var a=this._from;if(this._path.length>0)for(var b=0;b<this._path.length;b++)if(a=a[this._path[b]],!a)throw Error("unable to acces to the given property");return a}},{key:"_throwErrorIfAlreadyBinded",value:function(){if(this._binded)throw Error("Property already binded")}}]),a}();return a}});var e=Function.prototype.bind;angular.module("PropertyBinder").service("PropertyBinder.services.binder",["PropertyBinder.providers.binder",function(a){return function(){for(var b=arguments.length,c=Array(b),d=0;b>d;d++)c[d]=arguments[d];return new(e.apply(a,[null].concat(c)))}}])}(window,window.document,window.angular);