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

Commit a558a26

Browse files
committed
fix(watch_group): prevent removed watches from firing
1 parent 9316978 commit a558a26

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/change_detection/watch_group.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ class Watch {
418418
get expression => _record.handler.expression;
419419

420420
void invoke() {
421+
if (_deleted || !_dirty) return;
421422
_dirty = false;
422423
reactionFn(_record.currentValue, _record.previousValue);
423424
}

test/change_detection/watch_group_spec.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ main() => describe('WatchGroup', () {
3434
logger = _logger;
3535
}));
3636

37+
describe('watch lifecycle', () {
38+
it('should prevent reaction fn on removed', () {
39+
context['a'] = 'hello';
40+
var watch ;
41+
watchGrp.watch(parse('a'), (v, p) {
42+
logger('removed');
43+
watch.remove();
44+
});
45+
watch = watchGrp.watch(parse('a'), (v, p) => logger(v));
46+
watchGrp.detectChanges();
47+
expect(logger).toEqual(['removed']);
48+
});
49+
});
50+
3751
describe('property chaining', () {
3852
it('should read property', () {
3953
context['a'] = 'hello';

0 commit comments

Comments
 (0)