aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisko Hevery2011-08-11 15:02:08 -0700
committerMisko Hevery2011-08-12 15:47:44 -0700
commit1c9fc1e1dec67c8c05f02da1e0853439238c4d8e (patch)
treeb943174db170b198924b162eac523f6d50f52245
parent8bc7beacd80814102a6b08b83283ccf8614e44d4 (diff)
downloadangular.js-1c9fc1e1dec67c8c05f02da1e0853439238c4d8e.tar.bz2
fix(scope): rerun $digest from root, rather then per scope.
-rw-r--r--src/Scope.js13
-rw-r--r--test/ScopeSpec.js9
2 files changed, 16 insertions, 6 deletions
diff --git a/src/Scope.js b/src/Scope.js
index 572e9760..370c4bec 100644
--- a/src/Scope.js
+++ b/src/Scope.js
@@ -389,14 +389,15 @@ Scope.prototype = {
watch, value, last,
watchers = this.$$watchers,
length, count = 0,
- iterationCount, ttl = 100;
+ dirtyCount, ttl = 100,
+ recheck = !this.$parent || !this.$parent.$$phase;
if (this.$$phase) {
throw Error(this.$$phase + ' already in progress');
}
this.$$phase = '$digest';
do {
- iterationCount = 0;
+ dirtyCount = 0;
if (watchers) {
// process our watches
length = watchers.length;
@@ -406,7 +407,7 @@ Scope.prototype = {
// Most common watches are on primitives, in which case we can short
// circuit it with === operator, only when === fails do we use .equals
if ((value = watch.get(this)) !== (last = watch.last) && !equals(value, last)) {
- iterationCount++;
+ dirtyCount++;
watch.fn(this, watch.last = copy(value), last);
}
} catch (e) {
@@ -416,14 +417,14 @@ Scope.prototype = {
}
child = this.$$childHead;
while(child) {
- iterationCount += child.$digest();
+ dirtyCount += child.$digest();
child = child.$$nextSibling;
}
- count += iterationCount;
+ count += dirtyCount;
if(!(ttl--)) {
throw Error('100 $digest() iterations reached. Aborting!');
}
- } while (iterationCount);
+ } while (recheck && dirtyCount);
this.$$phase = null;
return count;
},
diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js
index a2ad57a3..6105df21 100644
--- a/test/ScopeSpec.js
+++ b/test/ScopeSpec.js
@@ -178,6 +178,15 @@ describe('Scope', function(){
expect(log).toEqual('abc');
});
+ it('should repeat watch cycle from the root elemnt', function(){
+ var log = '';
+ var child = root.$new();
+ root.$watch(function(){ log += 'a'; });
+ child.$watch(function(){ log += 'b'; });
+ root.$digest();
+ expect(log).toEqual('abab');
+ });
+
it('should prevent infinite recursion', function(){
root.$watch('a', function(self, v){self.b++;});