Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 5a36808

Browse files
committed
fix(scope): add scope id for easier debugging.
1 parent 322f2b6 commit 5a36808

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/core/scope.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ class ScopeLocals implements Map {
133133
* for change detection, change processing and memory management.
134134
*/
135135
class Scope {
136+
final String id;
137+
int _childScopeNextId = 0;
136138

137139
/**
138140
* The default execution context for [watch]es [observe]ers, and [eval]uation.
@@ -182,7 +184,7 @@ class Scope {
182184
bool get hasOwnStreams => _streams != null && _streams._scope == this;
183185

184186
Scope(Object this.context, this.rootScope, this._parentScope,
185-
this._readWriteGroup, this._readOnlyGroup);
187+
this._readWriteGroup, this._readOnlyGroup, this.id);
186188

187189
/**
188190
* A [watch] sets up a watch in the [digest] phase of the [apply] cycle.
@@ -271,7 +273,8 @@ class Scope {
271273
assert(isAttached);
272274
var child = new Scope(childContext, rootScope, this,
273275
_readWriteGroup.newGroup(childContext),
274-
_readOnlyGroup.newGroup(childContext));
276+
_readOnlyGroup.newGroup(childContext),
277+
'$id:${_childScopeNextId++}');
275278

276279
var prev = _childTail;
277280
child._prev = prev;
@@ -422,7 +425,8 @@ class RootScope extends Scope {
422425
this._scopeStats)
423426
: super(context, null, null,
424427
new RootWatchGroup(new DirtyCheckingChangeDetector(cacheGetter), context),
425-
new RootWatchGroup(new DirtyCheckingChangeDetector(cacheGetter), context))
428+
new RootWatchGroup(new DirtyCheckingChangeDetector(cacheGetter), context),
429+
'')
426430
{
427431
_zone.onTurnDone = apply;
428432
_zone.onError = (e, s, ls) => _exceptionHandler(e, s);

test/core/scope_spec.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,13 @@ void main() {
224224
describe('parent', () {
225225
it('should not have parent', inject((RootScope rootScope) {
226226
expect(rootScope.parentScope).toEqual(null);
227+
expect(rootScope.id).toEqual('');
227228
}));
228229

229230

230231
it('should point to parent', inject((RootScope rootScope) {
231232
var child = rootScope.createChild(new PrototypeMap(rootScope.context));
233+
expect(child.id).toEqual(':0');
232234
expect(rootScope.parentScope).toEqual(null);
233235
expect(child.parentScope).toEqual(rootScope);
234236
expect(child.createChild(new PrototypeMap(rootScope.context)).parentScope).toEqual(child);

0 commit comments

Comments
 (0)