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

Commit 1188ab0

Browse files
committed
chore(scope): add assert that scope is attached
1 parent e719e75 commit 1188ab0

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

lib/core/scope.dart

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class Scope {
150150
* The parent [Scope].
151151
*/
152152
Scope get parentScope => _parentScope;
153+
bool get isAttached => _parentScope == null ? false : _parentScope.isAttached;
153154

154155
// TODO(misko): WatchGroup should be private.
155156
// Instead we should expose performance stats about the watches
@@ -174,6 +175,7 @@ class Scope {
174175
*/
175176
Watch watch(expression, ReactionFn reactionFn,
176177
{context, FilterMap filters, bool readOnly: false}) {
178+
assert(isAttached);
177179
assert(expression != null);
178180
AST ast;
179181
Watch watch;
@@ -205,6 +207,7 @@ class Scope {
205207
}
206208

207209
dynamic eval(expression, [Map locals]) {
210+
assert(isAttached);
208211
assert(expression == null ||
209212
expression is String ||
210213
expression is Function);
@@ -235,13 +238,21 @@ class Scope {
235238
}
236239
}
237240

238-
ScopeEvent emit(String name, [data]) => _Streams.emit(this, name, data);
239-
ScopeEvent broadcast(String name, [data]) =>
240-
_Streams.broadcast(this, name, data);
241-
ScopeStream on(String name) =>
242-
_Streams.on(this, rootScope._exceptionHandler, name);
241+
ScopeEvent emit(String name, [data]) {
242+
assert(isAttached);
243+
return _Streams.emit(this, name, data);
244+
}
245+
ScopeEvent broadcast(String name, [data]) {
246+
assert(isAttached);
247+
return _Streams.broadcast(this, name, data);
248+
}
249+
ScopeStream on(String name) {
250+
assert(isAttached);
251+
return _Streams.on(this, rootScope._exceptionHandler, name);
252+
}
243253

244254
Scope createChild(Object childContext) {
255+
assert(isAttached);
245256
var child = new Scope(childContext, rootScope, this,
246257
_depth + 1, _nextChildIndex++,
247258
_readWriteGroup.newGroup(childContext),
@@ -256,6 +267,10 @@ class Scope {
256267
}
257268

258269
void destroy() {
270+
assert(isAttached);
271+
broadcast(ScopeEvent.DESTROY);
272+
_Streams.destroy(this);
273+
259274
var prev = _prev;
260275
var next = _next;
261276
if (prev == null) {
@@ -273,10 +288,7 @@ class Scope {
273288

274289
_readWriteGroup.remove();
275290
_readOnlyGroup.remove();
276-
_Streams.destroy(this);
277-
278291
_parentScope = null;
279-
broadcast(ScopeEvent.DESTROY);
280292
}
281293
}
282294

@@ -313,6 +325,7 @@ class RootScope extends Scope {
313325
}
314326

315327
RootScope get rootScope => this;
328+
bool get isAttached => true;
316329

317330
void digest() {
318331
_transitionState(null, STATE_DIGEST);
@@ -437,6 +450,7 @@ class RootScope extends Scope {
437450
void destroy() {}
438451

439452
void _transitionState(String from, String to) {
453+
assert(isAttached);
440454
if (_state != from) throw "$_state already in progress can not enter $to.";
441455
_state = to;
442456
}

0 commit comments

Comments
 (0)