6
6
* bind to a new instance of elements. It also provides a list
7
7
* of child paths which contain child templates
8
8
*/
9
- function Template ( priority ) {
9
+ function Template ( ) {
10
10
this . paths = [ ] ;
11
11
this . children = [ ] ;
12
- this . inits = [ ] ;
13
- this . priority = priority ;
12
+ this . linkFns = [ ] ;
14
13
this . newScope = false ;
15
14
}
16
15
17
16
Template . prototype = {
18
- attach : function ( element , scope ) {
19
- var inits = { } ;
20
- this . collectInits ( element , inits , scope ) ;
21
- forEachSorted ( inits , function ( queue ) {
22
- forEach ( queue , function ( fn ) { fn ( ) ; } ) ;
23
- } ) ;
24
- } ,
25
-
26
- collectInits : function ( element , inits , scope ) {
27
- var queue = inits [ this . priority ] , childScope = scope ;
28
- if ( ! queue ) {
29
- inits [ this . priority ] = queue = [ ] ;
30
- }
17
+ link : function ( element , scope ) {
18
+ var childScope = scope ;
31
19
if ( this . newScope ) {
32
20
childScope = isFunction ( this . newScope ) ? scope . $new ( this . newScope ( scope ) ) : scope . $new ( ) ;
33
21
element . data ( $$scope , childScope ) ;
34
22
}
35
- // TODO(misko): refactor this!!!
36
- // Why are inits even here?
37
- forEach ( this . inits , function ( fn ) {
38
- queue . push ( function ( ) {
39
- childScope . $eval ( function ( ) {
40
- try {
41
- return childScope . $service . invoke ( childScope , fn , [ element ] ) ;
42
- } catch ( e ) {
43
- childScope . $service ( '$exceptionHandler' ) ( e ) ;
44
- }
45
- } ) ;
46
- } ) ;
23
+ forEach ( this . linkFns , function ( fn ) {
24
+ try {
25
+ childScope . $service . invoke ( childScope , fn , [ element ] ) ;
26
+ } catch ( e ) {
27
+ childScope . $service ( '$exceptionHandler' ) ( e ) ;
28
+ }
47
29
} ) ;
48
30
var i ,
49
31
childNodes = element [ 0 ] . childNodes ,
50
32
children = this . children ,
51
33
paths = this . paths ,
52
34
length = paths . length ;
53
35
for ( i = 0 ; i < length ; i ++ ) {
54
- children [ i ] . collectInits ( jqLite ( childNodes [ paths [ i ] ] ) , inits , childScope ) ;
36
+ children [ i ] . link ( jqLite ( childNodes [ paths [ i ] ] ) , childScope ) ;
55
37
}
56
38
} ,
57
39
58
40
59
- addInit :function ( linkingFn ) {
41
+ addLinkFn :function ( linkingFn ) {
60
42
if ( linkingFn ) {
61
43
if ( ! linkingFn . $inject )
62
44
linkingFn . $inject = [ ] ;
63
- this . inits . push ( linkingFn ) ;
45
+ this . linkFns . push ( linkingFn ) ;
64
46
}
65
47
} ,
66
48
@@ -73,7 +55,7 @@ Template.prototype = {
73
55
} ,
74
56
75
57
empty : function ( ) {
76
- return this . inits . length === 0 && this . paths . length === 0 ;
58
+ return this . linkFns . length === 0 && this . paths . length === 0 ;
77
59
}
78
60
} ;
79
61
@@ -211,7 +193,7 @@ Compiler.prototype = {
211
193
}
212
194
}
213
195
}
214
- template = this . templatize ( templateElement , index , 0 ) || new Template ( ) ;
196
+ template = this . templatize ( templateElement , index ) || new Template ( ) ;
215
197
return function ( scope , cloneConnectFn ) {
216
198
// important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
217
199
// and sometimes changes the structure of the DOM.
@@ -222,69 +204,12 @@ Compiler.prototype = {
222
204
element . data ( $$scope , scope ) ;
223
205
scope . $element = element ;
224
206
( cloneConnectFn || noop ) ( element , scope ) ;
225
- template . attach ( element , scope ) ;
207
+ template . link ( element , scope ) ;
226
208
return scope ;
227
209
} ;
228
210
} ,
229
211
230
-
231
- /**
232
- * @workInProgress
233
- * @ngdoc directive
234
- * @name angular.directive.ng:eval-order
235
- * @deprecated
236
- *
237
- * @description
238
- * Normally the view is updated from top to bottom. This usually is
239
- * not a problem, but under some circumstances the values for data
240
- * is not available until after the full view is computed. If such
241
- * values are needed before they are computed the order of
242
- * evaluation can be changed using ng:eval-order
243
- *
244
- * @element ANY
245
- * @param {integer|string= } [priority=0] priority integer, or FIRST, LAST constant
246
- *
247
- * @example
248
- * try changing the invoice and see that the Total will lag in evaluation
249
- * @example
250
- <doc:example>
251
- <doc:source>
252
- <div>TOTAL: without ng:eval-order {{ total | currency }}</div>
253
- <div ng:eval-order='LAST'>TOTAL: with ng:eval-order {{ total | currency }}</div>
254
- <table ng:init="items=[{qty:1, cost:9.99, desc:'gadget'}];total=0;">
255
- <tr>
256
- <td>QTY</td>
257
- <td>Description</td>
258
- <td>Cost</td>
259
- <td>Total</td>
260
- <td></td>
261
- </tr>
262
- <tr ng:repeat="item in items">
263
- <td><input name="item.qty"/></td>
264
- <td><input name="item.desc"/></td>
265
- <td><input name="item.cost"/></td>
266
- <td>{{item.qty * item.cost | currency}}</td>
267
- <td><a href="" ng:click="items.$remove(item)">X</a></td>
268
- </tr>
269
- <tr>
270
- <td colspan="3"><a href="" ng:click="items.$add()">add</a></td>
271
- <td>{{ total = items.$sum('qty*cost') | currency }}</td>
272
- </tr>
273
- </table>
274
- </doc:source>
275
- <doc:scenario>
276
- it('should check ng:format', function(){
277
- expect(using('.doc-example-live div:first').binding("total")).toBe('$0.00');
278
- expect(using('.doc-example-live div:last').binding("total")).toBe('$9.99');
279
- input('item.qty').enter('2');
280
- expect(using('.doc-example-live div:first').binding("total")).toBe('$9.99');
281
- expect(using('.doc-example-live div:last').binding("total")).toBe('$19.98');
282
- });
283
- </doc:scenario>
284
- </doc:example>
285
- */
286
-
287
- templatize : function ( element , elementIndex , priority ) {
212
+ templatize : function ( element , elementIndex ) {
288
213
var self = this ,
289
214
widget ,
290
215
fn ,
@@ -300,17 +225,8 @@ Compiler.prototype = {
300
225
directives : function ( value ) { if ( isDefined ( value ) ) directives = value ; return directives ; } ,
301
226
scope : function ( value ) { if ( isDefined ( value ) ) template . newScope = template . newScope || value ; return template . newScope ; }
302
227
} ;
303
- try {
304
- priority = element . attr ( 'ng:eval-order' ) || priority || 0 ;
305
- } catch ( e ) {
306
- // for some reason IE throws error under some weird circumstances. so just assume nothing
307
- priority = priority || 0 ;
308
- }
309
228
element . addClass ( elementNamespace ) ;
310
- if ( isString ( priority ) ) {
311
- priority = PRIORITY [ uppercase ( priority ) ] || parseInt ( priority , 10 ) ;
312
- }
313
- template = new Template ( priority ) ;
229
+ template = new Template ( ) ;
314
230
eachAttribute ( element , function ( value , name ) {
315
231
if ( ! widget ) {
316
232
if ( widget = self . widgets ( '@' + name ) ) {
@@ -330,7 +246,7 @@ Compiler.prototype = {
330
246
descend = false ;
331
247
directives = false ;
332
248
var parent = element . parent ( ) ;
333
- template . addInit ( widget . call ( selfApi , element ) ) ;
249
+ template . addLinkFn ( widget . call ( selfApi , element ) ) ;
334
250
if ( parent && parent [ 0 ] ) {
335
251
element = jqLite ( parent [ 0 ] . childNodes [ elementIndex ] ) ;
336
252
}
@@ -361,14 +277,14 @@ Compiler.prototype = {
361
277
fn = directiveFns [ name ] ;
362
278
if ( fn ) {
363
279
element . addClass ( 'ng-directive' ) ;
364
- template . addInit ( ( directiveFns [ name ] ) . call ( selfApi , value , element ) ) ;
280
+ template . addLinkFn ( ( directiveFns [ name ] ) . call ( selfApi , value , element ) ) ;
365
281
}
366
282
} ) ;
367
283
}
368
284
// Process non text child nodes
369
285
if ( descend ) {
370
286
eachNode ( element , function ( child , i ) {
371
- template . addChild ( i , self . templatize ( child , i , priority ) ) ;
287
+ template . addChild ( i , self . templatize ( child , i ) ) ;
372
288
} ) ;
373
289
}
374
290
return template . empty ( ) ? null : template ;
0 commit comments