From 5a36808736efae4760c8f9fdc5b291353ca9ec02 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 10 Mar 2014 16:28:57 -0700 Subject: [PATCH] fix(scope): add scope id for easier debugging. --- lib/core/scope.dart | 10 +++++++--- test/core/scope_spec.dart | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/core/scope.dart b/lib/core/scope.dart index 707d59568..33f9b02fe 100644 --- a/lib/core/scope.dart +++ b/lib/core/scope.dart @@ -133,6 +133,8 @@ class ScopeLocals implements Map { * for change detection, change processing and memory management. */ class Scope { + final String id; + int _childScopeNextId = 0; /** * The default execution context for [watch]es [observe]ers, and [eval]uation. @@ -182,7 +184,7 @@ class Scope { bool get hasOwnStreams => _streams != null && _streams._scope == this; Scope(Object this.context, this.rootScope, this._parentScope, - this._readWriteGroup, this._readOnlyGroup); + this._readWriteGroup, this._readOnlyGroup, this.id); /** * A [watch] sets up a watch in the [digest] phase of the [apply] cycle. @@ -271,7 +273,8 @@ class Scope { assert(isAttached); var child = new Scope(childContext, rootScope, this, _readWriteGroup.newGroup(childContext), - _readOnlyGroup.newGroup(childContext)); + _readOnlyGroup.newGroup(childContext), + '$id:${_childScopeNextId++}'); var prev = _childTail; child._prev = prev; @@ -422,7 +425,8 @@ class RootScope extends Scope { this._scopeStats) : super(context, null, null, new RootWatchGroup(new DirtyCheckingChangeDetector(cacheGetter), context), - new RootWatchGroup(new DirtyCheckingChangeDetector(cacheGetter), context)) + new RootWatchGroup(new DirtyCheckingChangeDetector(cacheGetter), context), + '') { _zone.onTurnDone = apply; _zone.onError = (e, s, ls) => _exceptionHandler(e, s); diff --git a/test/core/scope_spec.dart b/test/core/scope_spec.dart index c2d2259bb..6d1cc484f 100644 --- a/test/core/scope_spec.dart +++ b/test/core/scope_spec.dart @@ -224,11 +224,13 @@ void main() { describe('parent', () { it('should not have parent', inject((RootScope rootScope) { expect(rootScope.parentScope).toEqual(null); + expect(rootScope.id).toEqual(''); })); it('should point to parent', inject((RootScope rootScope) { var child = rootScope.createChild(new PrototypeMap(rootScope.context)); + expect(child.id).toEqual(':0'); expect(rootScope.parentScope).toEqual(null); expect(child.parentScope).toEqual(rootScope); expect(child.createChild(new PrototypeMap(rootScope.context)).parentScope).toEqual(child);