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

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

Issue 19771010: implement dirty checking for @observable objects (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: logging for loops in dirty checking Created 7 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 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 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
(...skipping 25 matching lines...) Expand all
36 var kind = isInsert ? 'insert' : isRemove ? 'remove' : 'set'; 36 var kind = isInsert ? 'insert' : isRemove ? 'remove' : 'set';
37 return '#<MapChangeRecord $kind $key>'; 37 return '#<MapChangeRecord $kind $key>';
38 } 38 }
39 } 39 }
40 40
41 /** 41 /**
42 * Represents an observable map of model values. If any items are added, 42 * Represents an observable map of model values. If any items are added,
43 * removed, or replaced, then observers that are listening to [changes] 43 * removed, or replaced, then observers that are listening to [changes]
44 * will be notified. 44 * will be notified.
45 */ 45 */
46 class ObservableMap<K, V> extends ObservableBase implements Map<K, V> { 46 class ObservableMap<K, V> extends ChangeNotifierBase implements Map<K, V> {
47 static const _LENGTH = const Symbol('length'); 47 static const _LENGTH = const Symbol('length');
48 48
49 final Map<K, V> _map; 49 final Map<K, V> _map;
50 50
51 /** Creates an observable map. */ 51 /** Creates an observable map. */
52 ObservableMap() : _map = new HashMap<K, V>(); 52 ObservableMap() : _map = new HashMap<K, V>();
53 53
54 /** Creates a new observable map using a [LinkedHashMap]. */ 54 /** Creates a new observable map using a [LinkedHashMap]. */
55 ObservableMap.linked() : _map = new LinkedHashMap<K, V>(); 55 ObservableMap.linked() : _map = new LinkedHashMap<K, V>();
56 56
(...skipping 85 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