Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 42062da

Browse files
committed
refactor(scope): remove $flush/$observe ng:eval/ng:eval-order
1 parent 1c9fc1e commit 42062da

35 files changed

+265
-987
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
- $route.onChange() callback (http://docs.angularjs.org/#!angular.service.$route)
1717
no longer has this bound.
1818
- Removed undocumented $config in root scope. (You should have not been depending on this.)
19+
- removed $flush()/$observe on scope
20+
- removed ng:eval/ng:eval-order since it is incompatible with $digest phase
21+
- ng:init and ng:controllers are now called in the order of declaration in HTML
1922

2023

2124

Rakefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ ANGULAR = [
2727
'src/service/log.js',
2828
'src/service/resource.js',
2929
'src/service/route.js',
30-
'src/service/updateView.js',
3130
'src/service/window.js',
3231
'src/service/xhr.bulk.js',
3332
'src/service/xhr.cache.js',

docs/src/templates/docs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function DocsController($location, $browser, $window, $cookies) {
2727
var i = self.pages.length;
2828
while (i--) {
2929
if (self.pages[i].id == self.partialId) {
30-
self.partialTitle = self.pages[i].name
30+
self.partialTitle = self.pages[i].name;
3131
break;
3232
}
3333
}
@@ -36,7 +36,7 @@ function DocsController($location, $browser, $window, $cookies) {
3636
delete self.partialId;
3737
}
3838
}
39-
})();
39+
});
4040

4141
this.getUrl = function(page){
4242
return '#!/' + page.section + '/' + page.id;

jsTestDriver-coverage.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ load:
3030
- src/service/log.js
3131
- src/service/resource.js
3232
- src/service/route.js
33-
- src/service/updateView.js
3433
- src/service/window.js
3534
- src/service/xhr.bulk.js
3635
- src/service/xhr.cache.js

jsTestDriver-jquery.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ load:
3030
- src/service/log.js
3131
- src/service/resource.js
3232
- src/service/route.js
33-
- src/service/updateView.js
3433
- src/service/window.js
3534
- src/service/xhr.bulk.js
3635
- src/service/xhr.cache.js

jsTestDriver.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ load:
3030
- src/service/log.js
3131
- src/service/resource.js
3232
- src/service/route.js
33-
- src/service/updateView.js
3433
- src/service/window.js
3534
- src/service/xhr.bulk.js
3635
- src/service/xhr.cache.js

src/Angular.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ var _undefined = undefined,
7777
NG_EXCEPTION = 'ng-exception',
7878
NG_VALIDATION_ERROR = 'ng-validation-error',
7979
NOOP = 'noop',
80-
PRIORITY_FIRST = -99999,
81-
PRIORITY_WATCH = -1000,
82-
PRIORITY_LAST = 99999,
83-
PRIORITY = {'FIRST': PRIORITY_FIRST, 'LAST': PRIORITY_LAST, 'WATCH':PRIORITY_WATCH},
8480
Error = window.Error,
8581
/** holds major version number for IE or NaN for real browsers */
8682
msie = parseInt((/msie (\d+)/.exec(lowercase(navigator.userAgent)) || [])[1], 10),

src/Compiler.js

Lines changed: 21 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -6,61 +6,43 @@
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

1716
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;
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

Comments
 (0)