OLD | NEW |
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 if (other is SplayTreeMap) { | 73 if (other is SplayTreeMap) { |
74 result = new ObservableMap<K, V>.sorted(); | 74 result = new ObservableMap<K, V>.sorted(); |
75 } else if (other is LinkedHashMap) { | 75 } else if (other is LinkedHashMap) { |
76 result = new ObservableMap<K, V>.linked(); | 76 result = new ObservableMap<K, V>.linked(); |
77 } else { | 77 } else { |
78 result = new ObservableMap<K, V>(); | 78 result = new ObservableMap<K, V>(); |
79 } | 79 } |
80 return result; | 80 return result; |
81 } | 81 } |
82 | 82 |
83 Iterable<K> get keys => _map.keys; | 83 @reflectable Iterable<K> get keys => _map.keys; |
84 | 84 |
85 Iterable<V> get values => _map.values; | 85 @reflectable Iterable<V> get values => _map.values; |
86 | 86 |
87 int get length =>_map.length; | 87 @reflectable int get length =>_map.length; |
88 | 88 |
89 bool get isEmpty => length == 0; | 89 @reflectable bool get isEmpty => length == 0; |
90 | 90 |
91 bool get isNotEmpty => !isEmpty; | 91 @reflectable bool get isNotEmpty => !isEmpty; |
92 | 92 |
93 bool containsValue(Object value) => _map.containsValue(value); | 93 @reflectable bool containsValue(Object value) => _map.containsValue(value); |
94 | 94 |
95 bool containsKey(Object key) => _map.containsKey(key); | 95 @reflectable bool containsKey(Object key) => _map.containsKey(key); |
96 | 96 |
97 V operator [](Object key) => _map[key]; | 97 @reflectable V operator [](Object key) => _map[key]; |
98 | 98 |
99 void operator []=(K key, V value) { | 99 @reflectable void operator []=(K key, V value) { |
100 int len = _map.length; | 100 int len = _map.length; |
101 V oldValue = _map[key]; | 101 V oldValue = _map[key]; |
102 _map[key] = value; | 102 _map[key] = value; |
103 if (hasObservers) { | 103 if (hasObservers) { |
104 if (len != _map.length) { | 104 if (len != _map.length) { |
105 notifyPropertyChange(#length, len, _map.length); | 105 notifyPropertyChange(#length, len, _map.length); |
106 notifyChange(new MapChangeRecord(key, isInsert: true)); | 106 notifyChange(new MapChangeRecord(key, isInsert: true)); |
107 } else if (!identical(oldValue, value)) { | 107 } else if (!identical(oldValue, value)) { |
108 notifyChange(new MapChangeRecord(key)); | 108 notifyChange(new MapChangeRecord(key)); |
109 } | 109 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } |
OLD | NEW |