1+ // angular-property-binder
2+ // version: 0.1.12
3+ // author: Gaignoux Nicolas
4+ // generated: Thu Apr 16 2015 19:20:53 GMT+0200 (Paris, Madrid (heure d’été))
5+ // Autogenerated, do not edit. All changes will be undone.
6+ ( function ( window , document , angular ) {
7+
8+ " use strict; " ;
9+ angular . module ( 'PropertyBinder' , [ ] ) ;
10+ var _classCallCheck = function ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( 'Cannot call a class as a function' ) ; } } ;
11+
12+ var _createClass = ( function ( ) { function defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( 'value' in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ) ( ) ;
13+
14+ angular . module ( 'PropertyBinder' ) . provider ( 'PropertyBinder.providers.binder' , function ( ) {
15+ this . $get = function ( ) {
16+ var Binder = ( function ( ) {
17+ function Binder ( ) {
18+ var properties = arguments [ 0 ] === undefined ? [ ] : arguments [ 0 ] ;
19+
20+ _classCallCheck ( this , Binder ) ;
21+
22+ this . _properties = properties instanceof Array ? properties : [ properties ] ;
23+ this . _binded = false ;
24+ this . _sealed = false ;
25+ this . _to = undefined ;
26+ this . _from = undefined ;
27+ this . _path = [ ] ;
28+ this . _aliases = { } ;
29+ this . _change = function ( ) { } ;
30+ }
31+
32+ _createClass ( Binder , [ {
33+ key : 'from' ,
34+ value : function from ( scope ) {
35+ var path = arguments [ 1 ] === undefined ? [ ] : arguments [ 1 ] ;
36+
37+ this . _throwErrorIfAlreadyBinded ( ) ;
38+ this . _path = typeof path === 'string' ? path = path . split ( '.' ) : path ;
39+ this . _from = scope ;
40+ return this ;
41+ }
42+ } , {
43+ key : 'to' ,
44+ value : function to ( scope ) {
45+ this . _throwErrorIfAlreadyBinded ( ) ;
46+
47+ this . _to = scope ;
48+ return this ;
49+ }
50+ } , {
51+ key : 'as' ,
52+ value : function as ( ) {
53+ var aliases = arguments [ 0 ] === undefined ? { } : arguments [ 0 ] ;
54+
55+ this . _throwErrorIfAlreadyBinded ( ) ;
56+
57+ if ( aliases instanceof Object ) {
58+
59+ if ( aliases instanceof Array ) {
60+ for ( var i = 0 ; i < aliases . length ; i ++ ) {
61+ if ( ! ! this . _properties [ i ] ) this . _aliases [ this . _properties [ i ] ] = aliases [ i ] ;
62+ }
63+ } else this . _aliases = aliases ;
64+ } else {
65+
66+ if ( typeof aliases === 'string' ) {
67+ if ( this . _properties . length === 1 ) {
68+ var alias = aliases ;
69+ this . _aliases = { } ;
70+ this . _aliases [ this . _properties [ 0 ] ] = alias ;
71+ } else throw Error ( 'Ambiguous aliases' ) ;
72+ }
73+ }
74+
75+ return this ;
76+ }
77+ } , {
78+ key : 'onchange' ,
79+ value : function onchange ( ) {
80+ var changeEvent = arguments [ 0 ] === undefined ? function ( ) { } : arguments [ 0 ] ;
81+
82+ this . _change = changeEvent ;
83+ return this ;
84+ }
85+ } , {
86+ key : 'seal' ,
87+ value : function seal ( ) {
88+ this . _sealed = true ;
89+ return this ;
90+ }
91+ } , {
92+ key : 'unseal' ,
93+ value : function unseal ( ) {
94+ this . _sealed = false ;
95+ return this ;
96+ }
97+ } , {
98+ key : 'toggleSealing' ,
99+ value : function toggleSealing ( ) {
100+ this . _sealed = ! this . _sealed ;
101+ return this ;
102+ }
103+ } , {
104+ key : 'apply' ,
105+ value : function apply ( ) {
106+
107+ this . _throwErrorIfAlreadyBinded ( ) ;
108+ if ( this . _from && this . _to && this . _properties . length > 0 ) for ( var i = 0 ; i < this . _properties . length ; i ++ ) this . _createProperty ( this . _properties [ i ] ) ;
109+
110+ this . _binded = true ;
111+ return this ;
112+ }
113+ } , {
114+ key : 'destroy' ,
115+ value : function destroy ( ) {
116+
117+ for ( var i = 0 ; i < this . _properties . length ; i ++ ) this . _deleteProperty ( this . _properties [ i ] ) ;
118+
119+ this . _binded = false ;
120+ return this ;
121+ }
122+ } , {
123+ key : '_deleteProperty' ,
124+ value : function _deleteProperty ( property ) {
125+ var alias = this . _aliases [ property ] || property ;
126+ delete this . _to [ alias ] ;
127+ }
128+ } , {
129+ key : '_createProperty' ,
130+ value : function _createProperty ( property ) {
131+ var _this = this ;
132+
133+ Object . defineProperty ( this . _to , this . _aliases [ property ] || property , {
134+ enumerable : true ,
135+ configurable : true ,
136+ get : function get ( ) {
137+ var src = _this . _getSrc ( ) ;
138+ return src [ property ] instanceof Function ? src [ property ] . bind ( src ) : src [ property ] ;
139+ } ,
140+ set : function set ( value ) {
141+ if ( ! _this . _sealed ) {
142+ var src = _this . _getSrc ( ) ;
143+ var oldValue = src [ property ] ;
144+ src [ property ] = value ;
145+ if ( oldValue !== value ) _this . _change ( value , oldValue ) ;
146+ } else throw Error ( 'Trying to update a sealed property' ) ;
147+ }
148+ } ) ;
149+ }
150+ } , {
151+ key : '_getSrc' ,
152+ value : function _getSrc ( ) {
153+ var src = this . _from ;
154+ if ( this . _path . length > 0 ) for ( var i = 0 ; i < this . _path . length ; i ++ ) {
155+ src = src [ this . _path [ i ] ] ;
156+ if ( ! src ) throw Error ( 'unable to acces to the given property' ) ;
157+ }
158+ return src ;
159+ }
160+ } , {
161+ key : '_throwErrorIfAlreadyBinded' ,
162+ value : function _throwErrorIfAlreadyBinded ( ) {
163+ if ( this . _binded ) throw Error ( 'Property already binded' ) ;
164+ }
165+ } ] ) ;
166+
167+ return Binder ;
168+ } ) ( ) ;
169+
170+ return Binder ;
171+ } ;
172+ } ) ;
173+ var _bind = Function . prototype . bind ;
174+ angular . module ( 'PropertyBinder' ) . service ( 'PropertyBinder.services.binder' , [ 'PropertyBinder.providers.binder' , function ( Binder ) {
175+ return function ( ) {
176+ for ( var _len = arguments . length , parameters = Array ( _len ) , _key = 0 ; _key < _len ; _key ++ ) {
177+ parameters [ _key ] = arguments [ _key ] ;
178+ }
179+
180+ return new ( _bind . apply ( Binder , [ null ] . concat ( parameters ) ) ) ( ) ;
181+ } ;
182+ } ] ) ;
183+
184+ } ) ( window , window . document , window . angular ) ;
0 commit comments