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

Side by Side Diff: pkg/observe/lib/src/observable_map.dart

Issue 17552019: Reorganize mdv and observe packages (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: tests passing Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of mdv_observe; 5 part of observe;
6 6
7 // TODO(jmesserly): this needs to be faster. We currently require multiple 7 // TODO(jmesserly): this needs to be faster. We currently require multiple
8 // lookups per key to get the old value. 8 // lookups per key to get the old value.
9 // TODO(jmesserly): this doesn't implement the precise interfaces like 9 // TODO(jmesserly): this doesn't implement the precise interfaces like
10 // LinkedHashMap, SplayTreeMap or HashMap. However it can use them for the 10 // LinkedHashMap, SplayTreeMap or HashMap. However it can use them for the
11 // backing store. 11 // backing store.
12 12
13 // TODO(jmesserly): should we summarize map changes like we do for list changes? 13 // TODO(jmesserly): should we summarize map changes like we do for list changes?
14 class MapChangeRecord extends ChangeRecord { 14 class MapChangeRecord extends ChangeRecord {
15 /** The map key that changed. */ 15 /** The map key that changed. */
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 * Creates an observable map that contains all key value pairs of [other]. 61 * Creates an observable map that contains all key value pairs of [other].
62 * It will attempt to use the same backing map type if the other map is a 62 * It will attempt to use the same backing map type if the other map is a
63 * [LinkedHashMap], [SplayTreeMap], or [HashMap]. Otherwise it defaults to 63 * [LinkedHashMap], [SplayTreeMap], or [HashMap]. Otherwise it defaults to
64 * [HashMap]. 64 * [HashMap].
65 * 65 *
66 * Note this will perform a shallow conversion. If you want a deep conversion 66 * Note this will perform a shallow conversion. If you want a deep conversion
67 * you should use [toObservable]. 67 * you should use [toObservable].
68 */ 68 */
69 factory ObservableMap.from(Map<K, V> other) { 69 factory ObservableMap.from(Map<K, V> other) {
70 var result = new ObservableMap<K, V>._createFromType(other); 70 var result = new ObservableMap<K, V>._createFromType(other);
71 other.forEach((K key, V value) { result[key] = value; }); 71 other.forEach((key, value) { result[key] = value; });
justinfagnani 2013/06/25 23:03:31 Map has addAll() now: http://api.dartlang.org/docs
Jennifer Messerly 2013/06/26 23:09:12 filed a bug: https://code.google.com/p/dart/issues
72 return result; 72 return result;
73 } 73 }
74 74
75 factory ObservableMap._createFromType(Map<K, V> other) { 75 factory ObservableMap._createFromType(Map<K, V> other) {
76 ObservableMap result; 76 ObservableMap result;
77 if (other is SplayTreeMap) { 77 if (other is SplayTreeMap) {
78 result = new ObservableMap<K, V>.sorted(); 78 result = new ObservableMap<K, V>.sorted();
79 } else if (other is LinkedHashMap) { 79 } else if (other is LinkedHashMap) {
80 result = new ObservableMap<K, V>.linked(); 80 result = new ObservableMap<K, V>.linked();
81 } else { 81 } else {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 }); 142 });
143 notifyPropertyChange(_LENGTH, len, 0); 143 notifyPropertyChange(_LENGTH, len, 0);
144 } 144 }
145 _map.clear(); 145 _map.clear();
146 } 146 }
147 147
148 void forEach(void f(K key, V value)) => _map.forEach(f); 148 void forEach(void f(K key, V value)) => _map.forEach(f);
149 149
150 String toString() => Maps.mapToString(this); 150 String toString() => Maps.mapToString(this);
151 } 151 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698