Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(772)

Unified Diff: pkg/observe/lib/src/observable_map.dart

Issue 213743012: [observe] provide notifications of keys/values changed for ObservableMap (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/observe/test/observable_map_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/observe/lib/src/observable_map.dart
diff --git a/pkg/observe/lib/src/observable_map.dart b/pkg/observe/lib/src/observable_map.dart
index a46c6450ee626f2528ac413bed699287246fc5df..b09c4683a835634e3c7f3e1861e65cc4374b0c72 100644
--- a/pkg/observe/lib/src/observable_map.dart
+++ b/pkg/observe/lib/src/observable_map.dart
@@ -118,8 +118,10 @@ class ObservableMap<K, V> extends ChangeNotifier implements Map<K, V> {
if (len != _map.length) {
notifyPropertyChange(#length, len, _map.length);
notifyChange(new MapChangeRecord.insert(key, value));
+ _notifyKeysValuesChanged();
} else if (oldValue != value) {
notifyChange(new MapChangeRecord(key, oldValue, value));
+ _notifyValuesChanged();
}
}
@@ -133,6 +135,7 @@ class ObservableMap<K, V> extends ChangeNotifier implements Map<K, V> {
if (hasObservers && len != _map.length) {
notifyPropertyChange(#length, len, _map.length);
notifyChange(new MapChangeRecord.insert(key, result));
+ _notifyKeysValuesChanged();
}
return result;
}
@@ -143,6 +146,7 @@ class ObservableMap<K, V> extends ChangeNotifier implements Map<K, V> {
if (hasObservers && len != _map.length) {
notifyChange(new MapChangeRecord.remove(key, result));
notifyPropertyChange(#length, len, _map.length);
+ _notifyKeysValuesChanged();
}
return result;
}
@@ -154,6 +158,7 @@ class ObservableMap<K, V> extends ChangeNotifier implements Map<K, V> {
notifyChange(new MapChangeRecord.remove(key, value));
});
notifyPropertyChange(#length, len, 0);
+ _notifyKeysValuesChanged();
}
_map.clear();
}
@@ -161,4 +166,15 @@ class ObservableMap<K, V> extends ChangeNotifier implements Map<K, V> {
void forEach(void f(K key, V value)) => _map.forEach(f);
String toString() => Maps.mapToString(this);
+
+ // Note: we don't really have a reasonable old/new value to use here.
+ // But this should fix "keys" and "values" in templates with minimal overhead.
+ void _notifyKeysValuesChanged() {
+ notifyChange(new PropertyChangeRecord(this, #keys, null, null));
+ _notifyValuesChanged();
+ }
+
+ void _notifyValuesChanged() {
+ notifyChange(new PropertyChangeRecord(this, #values, null, null));
+ }
}
« no previous file with comments | « no previous file | pkg/observe/test/observable_map_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698