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

Commit 41694f3

Browse files
committed
Better fix for Record.remove() on detached group (stop the chain early)
1 parent abcef02 commit 41694f3

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/change_detector/change_detector.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ class Watch extends ChangeListener {
429429

430430
/// Calls the [_reactionFn] when the observed [Record] value changes
431431
void _onChange(value, previous) {
432+
assert(_triggerRecord._watchGroup.isAttached);
432433
super._onChange(value, previous);
433434
_reactionFn(value, previous);
434435
}
@@ -453,6 +454,8 @@ abstract class ChangeListener {
453454
/// current listener.
454455
void remove() {
455456
if (_triggerRecord != null) {
457+
// The [WatchGroup] has been detached, no need to remove individual [Record] / [Watch]
458+
if (!_triggerRecord._watchGroup.isAttached) return;
456459
if (identical(_triggerRecord._listenerHead, this)) {
457460
_triggerRecord._listenerHead = _listenerNext;
458461
if (_triggerRecord._listenerHead == null) {
@@ -714,8 +717,7 @@ class Record extends ChangeListener {
714717
}
715718

716719
void remove() {
717-
// Nothing to do as the [WatchGroup] has already been detached
718-
if (!_watchGroup.isAttached) return;
720+
assert(_watchGroup.isAttached);
719721

720722
// Update watch counters
721723
if (isCollectionMode) {

0 commit comments

Comments
 (0)