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

Unified Diff: packages/observable/lib/src/observable_map.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 years, 5 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
Index: packages/observable/lib/src/observable_map.dart
diff --git a/packages/observe/lib/src/observable_map.dart b/packages/observable/lib/src/observable_map.dart
similarity index 81%
rename from packages/observe/lib/src/observable_map.dart
rename to packages/observable/lib/src/observable_map.dart
index b09c4683a835634e3c7f3e1861e65cc4374b0c72..23a7f11fa483d9562e039e429aa9de0ae783ef1f 100644
--- a/packages/observe/lib/src/observable_map.dart
+++ b/packages/observable/lib/src/observable_map.dart
@@ -1,12 +1,14 @@
-// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-library observe.src.observable_map;
+library observable.src.observable_map;
import 'dart:collection';
-import 'package:observe/observe.dart';
+import 'change_record.dart' show ChangeRecord;
+import 'observable.dart' show Observable;
+import 'property_change_record.dart' show PropertyChangeRecord;
// TODO(jmesserly): this needs to be faster. We currently require multiple
// lookups per key to get the old value.
@@ -35,13 +37,18 @@ class MapChangeRecord<K, V> extends ChangeRecord {
final bool isRemove;
MapChangeRecord(this.key, this.oldValue, this.newValue)
- : isInsert = false, isRemove = false;
+ : isInsert = false,
+ isRemove = false;
MapChangeRecord.insert(this.key, this.newValue)
- : isInsert = true, isRemove = false, oldValue = null;
+ : isInsert = true,
+ isRemove = false,
+ oldValue = null;
MapChangeRecord.remove(this.key, this.oldValue)
- : isInsert = false, isRemove = true, newValue = null;
+ : isInsert = false,
+ isRemove = true,
+ newValue = null;
String toString() {
var kind = isInsert ? 'insert' : isRemove ? 'remove' : 'set';
@@ -52,7 +59,7 @@ class MapChangeRecord<K, V> extends ChangeRecord {
/// Represents an observable map of model values. If any items are added,
/// removed, or replaced, then observers that are listening to [changes]
/// will be notified.
-class ObservableMap<K, V> extends ChangeNotifier implements Map<K, V> {
+class ObservableMap<K, V> extends Observable implements Map<K, V> {
final Map<K, V> _map;
/// Creates an observable map.
@@ -77,7 +84,7 @@ class ObservableMap<K, V> extends ChangeNotifier implements Map<K, V> {
/// Like [ObservableMap.from], but creates an empty map.
factory ObservableMap.createFromType(Map<K, V> other) {
- ObservableMap result;
+ ObservableMap<K, V> result;
if (other is SplayTreeMap) {
result = new ObservableMap<K, V>.sorted();
} else if (other is LinkedHashMap) {
@@ -88,23 +95,23 @@ class ObservableMap<K, V> extends ChangeNotifier implements Map<K, V> {
return result;
}
- @reflectable Iterable<K> get keys => _map.keys;
+ Iterable<K> get keys => _map.keys;
- @reflectable Iterable<V> get values => _map.values;
+ Iterable<V> get values => _map.values;
- @reflectable int get length =>_map.length;
+ int get length => _map.length;
- @reflectable bool get isEmpty => length == 0;
+ bool get isEmpty => length == 0;
- @reflectable bool get isNotEmpty => !isEmpty;
+ bool get isNotEmpty => !isEmpty;
- @reflectable bool containsValue(Object value) => _map.containsValue(value);
+ bool containsValue(Object value) => _map.containsValue(value);
- @reflectable bool containsKey(Object key) => _map.containsKey(key);
+ bool containsKey(Object key) => _map.containsKey(key);
- @reflectable V operator [](Object key) => _map[key];
+ V operator [](Object key) => _map[key];
- @reflectable void operator []=(K key, V value) {
+ void operator []=(K key, V value) {
if (!hasObservers) {
_map[key] = value;
return;
@@ -126,7 +133,9 @@ class ObservableMap<K, V> extends ChangeNotifier implements Map<K, V> {
}
void addAll(Map<K, V> other) {
- other.forEach((K key, V value) { this[key] = value; });
+ other.forEach((K key, V value) {
+ this[key] = value;
+ });
}
V putIfAbsent(K key, V ifAbsent()) {
@@ -142,7 +151,7 @@ class ObservableMap<K, V> extends ChangeNotifier implements Map<K, V> {
V remove(Object key) {
int len = _map.length;
- V result = _map.remove(key);
+ V result = _map.remove(key);
if (hasObservers && len != _map.length) {
notifyChange(new MapChangeRecord.remove(key, result));
notifyPropertyChange(#length, len, _map.length);
« no previous file with comments | « packages/observable/lib/src/observable_list.dart ('k') | packages/observable/lib/src/property_change_record.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698