@@ -4,7 +4,7 @@ define(['exports', 'aurelia-metadata', 'aurelia-pal'], function (exports, _aurel
4
4
Object . defineProperty ( exports , "__esModule" , {
5
5
value : true
6
6
} ) ;
7
- exports . Container = exports . InvocationHandler = exports . _emptyParameters = exports . SingletonRegistration = exports . TransientRegistration = exports . FactoryInvoker = exports . NewInstance = exports . Factory = exports . StrategyResolver = exports . Parent = exports . Optional = exports . All = exports . Lazy = exports . resolver = undefined ;
7
+ exports . Container = exports . InvocationHandler = exports . _emptyParameters = exports . SingletonRegistration = exports . TransientRegistration = exports . FactoryInvoker = exports . NewInstance = exports . Factory = exports . Parent = exports . Optional = exports . All = exports . Lazy = exports . StrategyResolver = exports . resolver = undefined ;
8
8
exports . getDecoratorDependencies = getDecoratorDependencies ;
9
9
exports . lazy = lazy ;
10
10
exports . all = all ;
@@ -22,7 +22,7 @@ define(['exports', 'aurelia-metadata', 'aurelia-pal'], function (exports, _aurel
22
22
23
23
24
24
25
- var _dec , _class , _dec2 , _class3 , _dec3 , _class5 , _dec4 , _class7 , _dec5 , _class9 , _dec6 , _class11 , _dec7 , _class13 , _classInvokers ;
25
+ var _dec , _class , _dec2 , _class2 , _dec3 , _class3 , _dec4 , _class4 , _dec5 , _class5 , _dec6 , _class6 , _dec7 , _class7 , _classInvokers ;
26
26
27
27
var resolver = exports . resolver = _aureliaMetadata . protocol . create ( 'aurelia:resolver' , function ( target ) {
28
28
if ( ! ( typeof target . get === 'function' ) ) {
@@ -32,7 +32,39 @@ define(['exports', 'aurelia-metadata', 'aurelia-pal'], function (exports, _aurel
32
32
return true ;
33
33
} ) ;
34
34
35
- var Lazy = exports . Lazy = ( _dec = resolver ( ) , _dec ( _class = function ( ) {
35
+ var StrategyResolver = exports . StrategyResolver = ( _dec = resolver ( ) , _dec ( _class = function ( ) {
36
+ function StrategyResolver ( strategy , state ) {
37
+
38
+
39
+ this . strategy = strategy ;
40
+ this . state = state ;
41
+ }
42
+
43
+ StrategyResolver . prototype . get = function get ( container , key ) {
44
+ switch ( this . strategy ) {
45
+ case 0 :
46
+ return this . state ;
47
+ case 1 :
48
+ var _singleton = container . invoke ( this . state ) ;
49
+ this . state = _singleton ;
50
+ this . strategy = 0 ;
51
+ return _singleton ;
52
+ case 2 :
53
+ return container . invoke ( this . state ) ;
54
+ case 3 :
55
+ return this . state ( container , key , this ) ;
56
+ case 4 :
57
+ return this . state [ 0 ] . get ( container , key ) ;
58
+ case 5 :
59
+ return container . get ( this . state ) ;
60
+ default :
61
+ throw new Error ( 'Invalid strategy: ' + this . strategy ) ;
62
+ }
63
+ } ;
64
+
65
+ return StrategyResolver ;
66
+ } ( ) ) || _class ) ;
67
+ var Lazy = exports . Lazy = ( _dec2 = resolver ( ) , _dec2 ( _class2 = function ( ) {
36
68
function Lazy ( key ) {
37
69
38
70
@@ -52,8 +84,8 @@ define(['exports', 'aurelia-metadata', 'aurelia-pal'], function (exports, _aurel
52
84
} ;
53
85
54
86
return Lazy ;
55
- } ( ) ) || _class ) ;
56
- var All = exports . All = ( _dec2 = resolver ( ) , _dec2 ( _class3 = function ( ) {
87
+ } ( ) ) || _class2 ) ;
88
+ var All = exports . All = ( _dec3 = resolver ( ) , _dec3 ( _class3 = function ( ) {
57
89
function All ( key ) {
58
90
59
91
@@ -70,9 +102,9 @@ define(['exports', 'aurelia-metadata', 'aurelia-pal'], function (exports, _aurel
70
102
71
103
return All ;
72
104
} ( ) ) || _class3 ) ;
73
- var Optional = exports . Optional = ( _dec3 = resolver ( ) , _dec3 ( _class5 = function ( ) {
105
+ var Optional = exports . Optional = ( _dec4 = resolver ( ) , _dec4 ( _class4 = function ( ) {
74
106
function Optional ( key ) {
75
- var checkParent = arguments . length <= 1 || arguments [ 1 ] === undefined ? true : arguments [ 1 ] ;
107
+ var checkParent = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : true ;
76
108
77
109
78
110
@@ -89,14 +121,14 @@ define(['exports', 'aurelia-metadata', 'aurelia-pal'], function (exports, _aurel
89
121
} ;
90
122
91
123
Optional . of = function of ( key ) {
92
- var checkParent = arguments . length <= 1 || arguments [ 1 ] === undefined ? true : arguments [ 1 ] ;
124
+ var checkParent = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : true ;
93
125
94
126
return new Optional ( key , checkParent ) ;
95
127
} ;
96
128
97
129
return Optional ;
98
- } ( ) ) || _class5 ) ;
99
- var Parent = exports . Parent = ( _dec4 = resolver ( ) , _dec4 ( _class7 = function ( ) {
130
+ } ( ) ) || _class4 ) ;
131
+ var Parent = exports . Parent = ( _dec5 = resolver ( ) , _dec5 ( _class5 = function ( ) {
100
132
function Parent ( key ) {
101
133
102
134
@@ -112,55 +144,27 @@ define(['exports', 'aurelia-metadata', 'aurelia-pal'], function (exports, _aurel
112
144
} ;
113
145
114
146
return Parent ;
115
- } ( ) ) || _class7 ) ;
116
- var StrategyResolver = exports . StrategyResolver = ( _dec5 = resolver ( ) , _dec5 ( _class9 = function ( ) {
117
- function StrategyResolver ( strategy , state ) {
118
-
119
-
120
- this . strategy = strategy ;
121
- this . state = state ;
122
- }
123
-
124
- StrategyResolver . prototype . get = function get ( container , key ) {
125
- switch ( this . strategy ) {
126
- case 0 :
127
- return this . state ;
128
- case 1 :
129
- var singleton = container . invoke ( this . state ) ;
130
- this . state = singleton ;
131
- this . strategy = 0 ;
132
- return singleton ;
133
- case 2 :
134
- return container . invoke ( this . state ) ;
135
- case 3 :
136
- return this . state ( container , key , this ) ;
137
- case 4 :
138
- return this . state [ 0 ] . get ( container , key ) ;
139
- case 5 :
140
- return container . get ( this . state ) ;
141
- default :
142
- throw new Error ( 'Invalid strategy: ' + this . strategy ) ;
143
- }
144
- } ;
145
-
146
- return StrategyResolver ;
147
- } ( ) ) || _class9 ) ;
148
- var Factory = exports . Factory = ( _dec6 = resolver ( ) , _dec6 ( _class11 = function ( ) {
147
+ } ( ) ) || _class5 ) ;
148
+ var Factory = exports . Factory = ( _dec6 = resolver ( ) , _dec6 ( _class6 = function ( ) {
149
149
function Factory ( key ) {
150
150
151
151
152
152
this . _key = key ;
153
153
}
154
154
155
155
Factory . prototype . get = function get ( container ) {
156
- var _this2 = this ;
156
+ var fn = this . _key ;
157
+ var resolver = container . getResolver ( fn ) ;
158
+ if ( resolver && resolver . strategy === 3 ) {
159
+ fn = resolver . state ;
160
+ }
157
161
158
162
return function ( ) {
159
163
for ( var _len = arguments . length , rest = Array ( _len ) , _key = 0 ; _key < _len ; _key ++ ) {
160
164
rest [ _key ] = arguments [ _key ] ;
161
165
}
162
166
163
- return container . invoke ( _this2 . _key , rest ) ;
167
+ return container . invoke ( fn , rest ) ;
164
168
} ;
165
169
} ;
166
170
@@ -169,8 +173,8 @@ define(['exports', 'aurelia-metadata', 'aurelia-pal'], function (exports, _aurel
169
173
} ;
170
174
171
175
return Factory ;
172
- } ( ) ) || _class11 ) ;
173
- var NewInstance = exports . NewInstance = ( _dec7 = resolver ( ) , _dec7 ( _class13 = function ( ) {
176
+ } ( ) ) || _class6 ) ;
177
+ var NewInstance = exports . NewInstance = ( _dec7 = resolver ( ) , _dec7 ( _class7 = function ( ) {
174
178
function NewInstance ( key ) {
175
179
176
180
@@ -188,7 +192,14 @@ define(['exports', 'aurelia-metadata', 'aurelia-pal'], function (exports, _aurel
188
192
var dynamicDependencies = this . dynamicDependencies . length > 0 ? this . dynamicDependencies . map ( function ( dependency ) {
189
193
return dependency [ 'protocol:aurelia:resolver' ] ? dependency . get ( container ) : container . get ( dependency ) ;
190
194
} ) : undefined ;
191
- var instance = container . invoke ( this . key , dynamicDependencies ) ;
195
+
196
+ var fn = this . key ;
197
+ var resolver = container . getResolver ( fn ) ;
198
+ if ( resolver && resolver . strategy === 3 ) {
199
+ fn = resolver . state ;
200
+ }
201
+
202
+ var instance = container . invoke ( fn , dynamicDependencies ) ;
192
203
container . registerInstance ( this . asKey , instance ) ;
193
204
return instance ;
194
205
} ;
@@ -207,41 +218,34 @@ define(['exports', 'aurelia-metadata', 'aurelia-pal'], function (exports, _aurel
207
218
} ;
208
219
209
220
return NewInstance ;
210
- } ( ) ) || _class13 ) ;
211
- function getDecoratorDependencies ( target , name ) {
212
- var dependencies = target . inject ;
213
- if ( typeof dependencies === 'function' ) {
214
- throw new Error ( 'Decorator ' + name + ' cannot be used with "inject()". Please use an array instead.' ) ;
215
- }
216
- if ( ! dependencies ) {
217
- dependencies = _aureliaMetadata . metadata . getOwn ( _aureliaMetadata . metadata . paramTypes , target ) . slice ( ) ;
218
- target . inject = dependencies ;
219
- }
221
+ } ( ) ) || _class7 ) ;
222
+ function getDecoratorDependencies ( target ) {
223
+ autoinject ( target ) ;
220
224
221
- return dependencies ;
225
+ return target . inject ;
222
226
}
223
227
224
228
function lazy ( keyValue ) {
225
229
return function ( target , key , index ) {
226
- var params = getDecoratorDependencies ( target , 'lazy' ) ;
227
- params [ index ] = Lazy . of ( keyValue ) ;
230
+ var inject = getDecoratorDependencies ( target ) ;
231
+ inject [ index ] = Lazy . of ( keyValue ) ;
228
232
} ;
229
233
}
230
234
231
235
function all ( keyValue ) {
232
236
return function ( target , key , index ) {
233
- var params = getDecoratorDependencies ( target , 'all' ) ;
234
- params [ index ] = All . of ( keyValue ) ;
237
+ var inject = getDecoratorDependencies ( target ) ;
238
+ inject [ index ] = All . of ( keyValue ) ;
235
239
} ;
236
240
}
237
241
238
242
function optional ( ) {
239
- var checkParentOrTarget = arguments . length <= 0 || arguments [ 0 ] === undefined ? true : arguments [ 0 ] ;
243
+ var checkParentOrTarget = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : true ;
240
244
241
245
var deco = function deco ( checkParent ) {
242
246
return function ( target , key , index ) {
243
- var params = getDecoratorDependencies ( target , 'optional' ) ;
244
- params [ index ] = Optional . of ( params [ index ] , checkParent ) ;
247
+ var inject = getDecoratorDependencies ( target ) ;
248
+ inject [ index ] = Optional . of ( inject [ index ] , checkParent ) ;
245
249
} ;
246
250
} ;
247
251
if ( typeof checkParentOrTarget === 'boolean' ) {
@@ -251,15 +255,14 @@ define(['exports', 'aurelia-metadata', 'aurelia-pal'], function (exports, _aurel
251
255
}
252
256
253
257
function parent ( target , key , index ) {
254
- var params = getDecoratorDependencies ( target , 'parent' ) ;
255
- params [ index ] = Parent . of ( params [ index ] ) ;
258
+ var inject = getDecoratorDependencies ( target ) ;
259
+ inject [ index ] = Parent . of ( inject [ index ] ) ;
256
260
}
257
261
258
- function factory ( keyValue , asValue ) {
262
+ function factory ( keyValue ) {
259
263
return function ( target , key , index ) {
260
- var params = getDecoratorDependencies ( target , 'factory' ) ;
261
- var factory = Factory . of ( keyValue ) ;
262
- params [ index ] = asValue ? factory . as ( asValue ) : factory ;
264
+ var inject = getDecoratorDependencies ( target ) ;
265
+ inject [ index ] = Factory . of ( keyValue ) ;
263
266
} ;
264
267
}
265
268
@@ -270,10 +273,10 @@ define(['exports', 'aurelia-metadata', 'aurelia-pal'], function (exports, _aurel
270
273
271
274
var deco = function deco ( asKey ) {
272
275
return function ( target , key , index ) {
273
- var params = getDecoratorDependencies ( target , 'newInstance' ) ;
274
- params [ index ] = NewInstance . of . apply ( NewInstance , [ params [ index ] ] . concat ( dynamicDependencies ) ) ;
276
+ var inject = getDecoratorDependencies ( target ) ;
277
+ inject [ index ] = NewInstance . of . apply ( NewInstance , [ inject [ index ] ] . concat ( dynamicDependencies ) ) ;
275
278
if ( ! ! asKey ) {
276
- params [ index ] . as ( asKey ) ;
279
+ inject [ index ] . as ( asKey ) ;
277
280
}
278
281
} ;
279
282
} ;
@@ -344,7 +347,7 @@ define(['exports', 'aurelia-metadata', 'aurelia-pal'], function (exports, _aurel
344
347
}
345
348
346
349
function singleton ( keyOrRegisterInChild ) {
347
- var registerInChild = arguments . length <= 1 || arguments [ 1 ] === undefined ? false : arguments [ 1 ] ;
350
+ var registerInChild = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : false ;
348
351
349
352
return registration ( new SingletonRegistration ( keyOrRegisterInChild , registerInChild ) ) ;
350
353
}
@@ -366,7 +369,7 @@ define(['exports', 'aurelia-metadata', 'aurelia-pal'], function (exports, _aurel
366
369
367
370
var SingletonRegistration = exports . SingletonRegistration = function ( ) {
368
371
function SingletonRegistration ( keyOrRegisterInChild ) {
369
- var registerInChild = arguments . length <= 1 || arguments [ 1 ] === undefined ? false : arguments [ 1 ] ;
372
+ var registerInChild = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : false ;
370
373
371
374
372
375
@@ -581,7 +584,7 @@ define(['exports', 'aurelia-metadata', 'aurelia-pal'], function (exports, _aurel
581
584
} ;
582
585
583
586
Container . prototype . hasResolver = function hasResolver ( key ) {
584
- var checkParent = arguments . length <= 1 || arguments [ 1 ] === undefined ? false : arguments [ 1 ] ;
587
+ var checkParent = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : false ;
585
588
586
589
validateKey ( key ) ;
587
590
@@ -713,23 +716,8 @@ define(['exports', 'aurelia-metadata', 'aurelia-pal'], function (exports, _aurel
713
716
714
717
function autoinject ( potentialTarget ) {
715
718
var deco = function deco ( target ) {
716
- var previousInject = target . inject ? target . inject . slice ( ) : null ;
717
- var autoInject = _aureliaMetadata . metadata . getOwn ( _aureliaMetadata . metadata . paramTypes , target ) || _emptyParameters ;
718
- if ( ! previousInject ) {
719
- target . inject = autoInject ;
720
- } else {
721
- for ( var i = 0 ; i < autoInject . length ; i ++ ) {
722
- if ( previousInject [ i ] && previousInject [ i ] !== autoInject [ i ] ) {
723
- var prevIndex = previousInject . indexOf ( autoInject [ i ] ) ;
724
- if ( prevIndex > - 1 ) {
725
- previousInject . splice ( prevIndex , 1 ) ;
726
- }
727
- previousInject . splice ( prevIndex > - 1 && prevIndex < i ? i - 1 : i , 0 , autoInject [ i ] ) ;
728
- } else if ( ! previousInject [ i ] ) {
729
- previousInject [ i ] = autoInject [ i ] ;
730
- }
731
- }
732
- target . inject = previousInject ;
719
+ if ( ! target . hasOwnProperty ( 'inject' ) ) {
720
+ target . inject = ( _aureliaMetadata . metadata . getOwn ( _aureliaMetadata . metadata . paramTypes , target ) || _emptyParameters ) . slice ( ) ;
733
721
}
734
722
} ;
735
723
@@ -742,16 +730,11 @@ define(['exports', 'aurelia-metadata', 'aurelia-pal'], function (exports, _aurel
742
730
}
743
731
744
732
return function ( target , key , descriptor ) {
745
- if ( typeof descriptor === 'number' && rest . length === 1 ) {
746
- var params = target . inject ;
747
- if ( typeof params === 'function' ) {
748
- throw new Error ( 'Decorator inject cannot be used with "inject()". Please use an array instead.' ) ;
749
- }
750
- if ( ! params ) {
751
- params = _aureliaMetadata . metadata . getOwn ( _aureliaMetadata . metadata . paramTypes , target ) . slice ( ) ;
752
- target . inject = params ;
733
+ if ( typeof descriptor === 'number' ) {
734
+ autoinject ( target ) ;
735
+ if ( rest . length === 1 ) {
736
+ target . inject [ descriptor ] = rest [ 0 ] ;
753
737
}
754
- params [ descriptor ] = rest [ 0 ] ;
755
738
return ;
756
739
}
757
740
0 commit comments