66 * bind to a new instance of elements. It also provides a list
77 * of child paths which contain child templates
88 */
9- function Template ( priority ) {
9+ function Template ( ) {
1010 this . paths = [ ] ;
1111 this . children = [ ] ;
12- this . inits = [ ] ;
13- this . priority = priority ;
12+ this . linkFns = [ ] ;
1413 this . newScope = false ;
1514}
1615
1716Template . 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 ;
3119 if ( this . newScope ) {
3220 childScope = isFunction ( this . newScope ) ? scope . $new ( this . newScope ( scope ) ) : scope . $new ( ) ;
3321 element . data ( $$scope , childScope ) ;
3422 }
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+ }
4729 } ) ;
4830 var i ,
4931 childNodes = element [ 0 ] . childNodes ,
5032 children = this . children ,
5133 paths = this . paths ,
5234 length = paths . length ;
5335 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 ) ;
5537 }
5638 } ,
5739
5840
59- addInit :function ( linkingFn ) {
41+ addLinkFn :function ( linkingFn ) {
6042 if ( linkingFn ) {
6143 if ( ! linkingFn . $inject )
6244 linkingFn . $inject = [ ] ;
63- this . inits . push ( linkingFn ) ;
45+ this . linkFns . push ( linkingFn ) ;
6446 }
6547 } ,
6648
@@ -73,7 +55,7 @@ Template.prototype = {
7355 } ,
7456
7557 empty : function ( ) {
76- return this . inits . length === 0 && this . paths . length === 0 ;
58+ return this . linkFns . length === 0 && this . paths . length === 0 ;
7759 }
7860} ;
7961
@@ -211,7 +193,7 @@ Compiler.prototype = {
211193 }
212194 }
213195 }
214- template = this . templatize ( templateElement , index , 0 ) || new Template ( ) ;
196+ template = this . templatize ( templateElement , index ) || new Template ( ) ;
215197 return function ( scope , cloneConnectFn ) {
216198 // important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
217199 // and sometimes changes the structure of the DOM.
@@ -222,69 +204,12 @@ Compiler.prototype = {
222204 element . data ( $$scope , scope ) ;
223205 scope . $element = element ;
224206 ( cloneConnectFn || noop ) ( element , scope ) ;
225- template . attach ( element , scope ) ;
207+ template . link ( element , scope ) ;
226208 return scope ;
227209 } ;
228210 } ,
229211
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 ) {
288213 var self = this ,
289214 widget ,
290215 fn ,
@@ -300,17 +225,8 @@ Compiler.prototype = {
300225 directives : function ( value ) { if ( isDefined ( value ) ) directives = value ; return directives ; } ,
301226 scope : function ( value ) { if ( isDefined ( value ) ) template . newScope = template . newScope || value ; return template . newScope ; }
302227 } ;
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- }
309228 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 ( ) ;
314230 eachAttribute ( element , function ( value , name ) {
315231 if ( ! widget ) {
316232 if ( widget = self . widgets ( '@' + name ) ) {
@@ -330,7 +246,7 @@ Compiler.prototype = {
330246 descend = false ;
331247 directives = false ;
332248 var parent = element . parent ( ) ;
333- template . addInit ( widget . call ( selfApi , element ) ) ;
249+ template . addLinkFn ( widget . call ( selfApi , element ) ) ;
334250 if ( parent && parent [ 0 ] ) {
335251 element = jqLite ( parent [ 0 ] . childNodes [ elementIndex ] ) ;
336252 }
@@ -361,14 +277,14 @@ Compiler.prototype = {
361277 fn = directiveFns [ name ] ;
362278 if ( fn ) {
363279 element . addClass ( 'ng-directive' ) ;
364- template . addInit ( ( directiveFns [ name ] ) . call ( selfApi , value , element ) ) ;
280+ template . addLinkFn ( ( directiveFns [ name ] ) . call ( selfApi , value , element ) ) ;
365281 }
366282 } ) ;
367283 }
368284 // Process non text child nodes
369285 if ( descend ) {
370286 eachNode ( element , function ( child , i ) {
371- template . addChild ( i , self . templatize ( child , i , priority ) ) ;
287+ template . addChild ( i , self . templatize ( child , i ) ) ;
372288 } ) ;
373289 }
374290 return template . empty ( ) ? null : template ;
0 commit comments