@@ -150,6 +150,7 @@ class Scope {
150
150
* The parent [Scope] .
151
151
*/
152
152
Scope get parentScope => _parentScope;
153
+ bool get isAttached => _parentScope == null ? false : _parentScope.isAttached;
153
154
154
155
// TODO(misko): WatchGroup should be private.
155
156
// Instead we should expose performance stats about the watches
@@ -174,6 +175,7 @@ class Scope {
174
175
*/
175
176
Watch watch (expression, ReactionFn reactionFn,
176
177
{context, FilterMap filters, bool readOnly: false }) {
178
+ assert (isAttached);
177
179
assert (expression != null );
178
180
AST ast;
179
181
Watch watch;
@@ -205,6 +207,7 @@ class Scope {
205
207
}
206
208
207
209
dynamic eval (expression, [Map locals]) {
210
+ assert (isAttached);
208
211
assert (expression == null ||
209
212
expression is String ||
210
213
expression is Function );
@@ -235,13 +238,21 @@ class Scope {
235
238
}
236
239
}
237
240
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
+ }
243
253
244
254
Scope createChild (Object childContext) {
255
+ assert (isAttached);
245
256
var child = new Scope (childContext, rootScope, this ,
246
257
_depth + 1 , _nextChildIndex++ ,
247
258
_readWriteGroup.newGroup (childContext),
@@ -256,6 +267,10 @@ class Scope {
256
267
}
257
268
258
269
void destroy () {
270
+ assert (isAttached);
271
+ broadcast (ScopeEvent .DESTROY );
272
+ _Streams .destroy (this );
273
+
259
274
var prev = _prev;
260
275
var next = _next;
261
276
if (prev == null ) {
@@ -273,10 +288,7 @@ class Scope {
273
288
274
289
_readWriteGroup.remove ();
275
290
_readOnlyGroup.remove ();
276
- _Streams .destroy (this );
277
-
278
291
_parentScope = null ;
279
- broadcast (ScopeEvent .DESTROY );
280
292
}
281
293
}
282
294
@@ -313,6 +325,7 @@ class RootScope extends Scope {
313
325
}
314
326
315
327
RootScope get rootScope => this ;
328
+ bool get isAttached => true ;
316
329
317
330
void digest () {
318
331
_transitionState (null , STATE_DIGEST );
@@ -437,6 +450,7 @@ class RootScope extends Scope {
437
450
void destroy () {}
438
451
439
452
void _transitionState (String from, String to) {
453
+ assert (isAttached);
440
454
if (_state != from) throw "$_state already in progress can not enter $to ." ;
441
455
_state = to;
442
456
}
0 commit comments