@@ -429,10 +429,11 @@ class DirtyCheckingRecord<H> implements WatchRecord<H> {
429
429
static const int _MODE_GETTER_OR_METHOD_CLOSURE_ = 5 ;
430
430
static const int _MODE_GETTER_OBS_OR_METHOD_CLOSURE_ = 6 ;
431
431
static const int _MODE_MAP_FIELD_ = 7 ;
432
- static const int _MODE_ITERABLE_ = 8 ;
433
- static const int _MODE_LIST_NOTIFIED_ = 9 ;
434
- static const int _MODE_MAP_ = 10 ;
435
- static const int _MODE_MAP_NOTIFIED_ = 11 ;
432
+ static const int _MODE_MAP_FIELD_NOTIFIED_ = 8 ;
433
+ static const int _MODE_ITERABLE_ = 9 ;
434
+ static const int _MODE_LIST_NOTIFIED_ = 10 ;
435
+ static const int _MODE_MAP_ = 11 ;
436
+ static const int _MODE_MAP_NOTIFIED_ = 12 ;
436
437
437
438
final DirtyCheckingChangeDetectorGroup _group;
438
439
final FieldGetterFactory _fieldGetterFactory;
@@ -476,7 +477,7 @@ class DirtyCheckingRecord<H> implements WatchRecord<H> {
476
477
while (_object is ContextLocals ) {
477
478
var ctx = _object as ContextLocals ;
478
479
if (ctx.hasProperty (field)) {
479
- _mode = _MODE_MAP_FIELD_ ;
480
+ _mode = _MODE_MAP_FIELD_ ;
480
481
_getter = null ;
481
482
return ;
482
483
}
@@ -501,9 +502,9 @@ class DirtyCheckingRecord<H> implements WatchRecord<H> {
501
502
// mapping with the one from the new reference.
502
503
currentValue._revertToPreviousState ();
503
504
}
504
- if (_object is obs.ChangeNotifier ) {
505
+ if (_object is obs.Observable ) {
505
506
_mode = _MODE_MAP_NOTIFIED_ ; // Run the dccd after the map is added
506
- var subscription = (_object as obs.ChangeNotifier ).changes.listen ((_) {
507
+ var subscription = (_object as obs.Observable ).changes.listen ((_) {
507
508
_mode = _MODE_MAP_NOTIFIED_ ; // Run the dccd after the map is updated
508
509
});
509
510
_group._registerObservable (this , subscription);
@@ -536,10 +537,19 @@ class DirtyCheckingRecord<H> implements WatchRecord<H> {
536
537
}
537
538
538
539
if (_object is Map ) {
539
- _mode = _MODE_MAP_FIELD_ ;
540
- _getter = null ;
540
+ if (_object is obs.Observable ) {
541
+ _mode = _MODE_MAP_FIELD_NOTIFIED_ ;
542
+ var subscription = (_object as obs.Observable ).changes.listen ((_) {
543
+ _mode = _MODE_MAP_FIELD_NOTIFIED_ ; // Run the dccd after the map is updated
544
+ });
545
+ _group._registerObservable (this , subscription);
546
+ _getter = null ;
547
+ } else {
548
+ _mode = _MODE_MAP_FIELD_ ;
549
+ _getter = null ;
550
+ }
541
551
} else {
542
- _mode = _object is obs.ChangeNotifier ?
552
+ _mode = _object is obs.Observable ?
543
553
_MODE_GETTER_OBS_OR_METHOD_CLOSURE_ :
544
554
_MODE_GETTER_OR_METHOD_CLOSURE_ ;
545
555
_getter = _fieldGetterFactory.getter (_object, field);
@@ -579,9 +589,6 @@ class DirtyCheckingRecord<H> implements WatchRecord<H> {
579
589
_mode = _MODE_NOOP_ ;
580
590
if (current is ! Function || identical (current, _getter (object))) {
581
591
var subscription = (object as obs.Observable ).changes.listen ((records) {
582
- // todo(vicb) we should only go to the _MODE_GETTER_NOTIFIED_ mode when a record
583
- // is applicable to the current `field`. With the current implementation, any field
584
- // on an observable object will trigger this listener.
585
592
_mode = _MODE_GETTER_NOTIFIED_ ;
586
593
});
587
594
_group._registerObservable (this , subscription);
@@ -590,6 +597,10 @@ class DirtyCheckingRecord<H> implements WatchRecord<H> {
590
597
case _MODE_MAP_FIELD_ :
591
598
current = object[field];
592
599
break ;
600
+ case _MODE_MAP_FIELD_NOTIFIED_ :
601
+ _mode = _MODE_NOOP_ ; // no-op until next notification
602
+ current = object[field];
603
+ break ;
593
604
case _MODE_IDENTITY_ :
594
605
current = object;
595
606
_mode = _MODE_NOOP_ ;
0 commit comments