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

Commit 713307b

Browse files
author
Misko Hevery
committed
added ng-eval-order attribute
1 parent 841640e commit 713307b

File tree

7 files changed

+53
-13
lines changed

7 files changed

+53
-13
lines changed

angular-debug.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2788,9 +2788,9 @@ foreach({
27882788
});
27892789
}
27902790

2791-
if (state === null){
2791+
if (state === null && this['$invalidWidgets']){
27922792
// request in flight, mark widget invalid, but don't show it to user
2793-
(this['$invalidWidgets']||[]).push(this.$element);
2793+
this['$invalidWidgets'].markInvalid(this.$element);
27942794
}
27952795
return state;
27962796
}

src/Angular.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var consoleNode,
99
PRIORITY_FIRST = -99999,
1010
PRIORITY_WATCH = -1000,
1111
PRIORITY_LAST = 99999,
12+
PRIORITY = {'FIRST': PRIORITY_FIRST, 'LAST': PRIORITY_LAST, 'WATCH':PRIORITY_WATCH},
1213
NOOP = 'noop',
1314
NG_EXCEPTION = 'ng-exception',
1415
NG_VALIDATION_ERROR = 'ng-validation-error',

src/Compiler.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,34 @@
44
* bind to a new instance of elements. It also provides a list
55
* of child paths which contain child templates
66
*/
7-
function Template() {
7+
function Template(priority) {
88
this.paths = [];
99
this.children = [];
1010
this.inits = [];
11+
this.priority = priority || 0;
1112
}
1213

1314
Template.prototype = {
1415
init: function(element, scope) {
16+
var inits = {};
17+
this.collectInits(element, inits);
18+
foreachSorted(inits, function(queue){
19+
foreach(queue, function(fn){
20+
fn(scope);
21+
});
22+
});
23+
},
24+
25+
collectInits: function(element, inits) {
26+
var queue = inits[this.priority];
27+
if (!queue) {
28+
inits[this.priority] = queue = [];
29+
}
1530
element = jqLite(element);
1631
foreach(this.inits, function(fn) {
17-
scope.$tryEval(fn, element, element);
32+
queue.push(function(scope) {
33+
scope.$tryEval(fn, element, element);
34+
});
1835
});
1936

2037
var i,
@@ -23,7 +40,7 @@ Template.prototype = {
2340
paths = this.paths,
2441
length = paths.length;
2542
for (i = 0; i < length; i++) {
26-
children[i].init(childNodes[paths[i]], scope);
43+
children[i].collectInits(childNodes[paths[i]], inits);
2744
}
2845
},
2946

@@ -78,13 +95,13 @@ Compiler.prototype = {
7895
};
7996
},
8097

81-
templatize: function(element){
98+
templatize: function(element, priority){
8299
var self = this,
83100
widget,
84101
directiveFns = self.directives,
85102
descend = true,
86103
directives = true,
87-
template = new Template(),
104+
template,
88105
selfApi = {
89106
compile: bind(self, self.compile),
90107
comment:function(text) {return jqLite(document.createComment(text));},
@@ -93,7 +110,11 @@ Compiler.prototype = {
93110
descend: function(value){ if(isDefined(value)) descend = value; return descend;},
94111
directives: function(value){ if(isDefined(value)) directives = value; return directives;}
95112
};
96-
113+
priority = element.attr('ng-eval-order') || priority || 0;
114+
if (isString(priority)) {
115+
priority = PRIORITY[uppercase(priority)] || 0;
116+
}
117+
template = new Template(priority);
97118
eachAttribute(element, function(value, name){
98119
if (!widget) {
99120
if (widget = self.widgets['@' + name]) {
@@ -135,7 +156,7 @@ Compiler.prototype = {
135156
// Process non text child nodes
136157
if (descend) {
137158
eachNode(element, function(child, i){
138-
template.addChild(i, self.templatize(child));
159+
template.addChild(i, self.templatize(child, priority));
139160
});
140161
}
141162
return template.empty() ? null : template;

test/ApiTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,5 +252,5 @@ ApiTest.prototype.testStringFromUTC = function(){
252252
};
253253

254254
ApiTest.prototype.testObjectShouldHaveExtend = function(){
255-
assertEquals(angular.Object.extend, extend);
255+
assertEquals({a:1, b:2}, angular.Object.extend({a:1}, {b:2}));
256256
};

test/CompilerSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe('compiler', function(){
7272
var scope = compile('<span hello="misko" stop="true"><span hello="adam"/></span>');
7373
expect(log).toEqual("hello misko");
7474
});
75-
75+
7676
it('should allow creation of templates', function(){
7777
directives.duplicate = function(expr, element){
7878
element.replaceWith(document.createComment("marker"));

test/ValidatorsTest.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,15 @@ describe('Validator:asynchronous', function(){
8888
var value, fn;
8989

9090
beforeEach(function(){
91+
var invalidWidgets = [];
92+
invalidWidgets.markInvalid = function(element){
93+
invalidWidgets.push(element);
94+
};
9195
value = null;
9296
fn = null;
9397
self = {
9498
$element:jqLite('<input />'),
95-
$invalidWidgets:[],
99+
$invalidWidgets:invalidWidgets,
96100
$updateView: noop
97101
};
98102
});
@@ -125,7 +129,7 @@ describe('Validator:asynchronous', function(){
125129
it("should not make second request to same value", function(){
126130
asynchronous.call(self, "kai", function(v,f){value=v; fn=f;});
127131
expect(value).toEqual('kai');
128-
expect(self.$invalidWidgets).toEqual([self.$element]);
132+
expect(self.$invalidWidgets[0][0]).toEqual(self.$element[0]);
129133

130134
var spy = jasmine.createSpy();
131135
asynchronous.call(self, "kai", spy);

test/directivesSpec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,18 @@ describe("directives", function(){
181181
expect(scope.greet('misko')).toEqual('hello misko!');
182182
delete window.Greeter;
183183
});
184+
185+
it('should eval things according to ng-eval-order', function(){
186+
var scope = compile(
187+
'<div ng-init="log=\'\'">' +
188+
'{{log = log + \'e\'}}' +
189+
'<span ng-eval-order="first" ng-eval="log = log + \'a\'">' +
190+
'{{log = log + \'b\'}}' +
191+
'<span src="{{log = log + \'c\'}}"></span>' +
192+
'<span bind-template="{{log = log + \'d\'}}"></span>' +
193+
'</span>' +
194+
'</div>');
195+
expect(scope.log).toEqual('abcde');
196+
});
197+
184198
});

0 commit comments

Comments
 (0)