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 library web_ui.observe.map; | 5 library web_ui.observe.map; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 import 'observable.dart'; | 8 import 'observable.dart'; |
9 | 9 |
10 typedef Map<K, V> MapFactory<K, V>(); | 10 typedef Map<K, V> MapFactory<K, V>(); |
(...skipping 25 matching lines...) Expand all Loading... |
36 // TODO(jmesserly): removed type annotation to workaround: | 36 // TODO(jmesserly): removed type annotation to workaround: |
37 // https://code.google.com/p/dart/issues/detail?id=11540 | 37 // https://code.google.com/p/dart/issues/detail?id=11540 |
38 ObservableMap.linked() : this(createMap: () => new LinkedHashMap/*<K, V>*/()); | 38 ObservableMap.linked() : this(createMap: () => new LinkedHashMap/*<K, V>*/()); |
39 | 39 |
40 /** Creates a new observable map using a [SplayTreeMap]. */ | 40 /** Creates a new observable map using a [SplayTreeMap]. */ |
41 ObservableMap.sorted() : this(createMap: () => new SplayTreeMap/*<K, V>*/()); | 41 ObservableMap.sorted() : this(createMap: () => new SplayTreeMap/*<K, V>*/()); |
42 | 42 |
43 /** | 43 /** |
44 * Creates an observable map that contains all key value pairs of [other]. | 44 * Creates an observable map that contains all key value pairs of [other]. |
45 */ | 45 */ |
46 factory ObservableMap.from(Map<K, V> other, {MapFactory<K, V> createMap}) { | 46 factory ObservableMap.from(Map/*<K, V>*/ other, |
47 var result = new ObservableMap<K, V>(createMap: createMap); | 47 {MapFactory/*<K, V>*/ createMap}) { |
48 other.forEach((K key, V value) { result[key] = value; }); | 48 var result = new ObservableMap/*<K, V>*/(createMap: createMap); |
| 49 other.forEach((/*K*/ key, /*V*/value) { result[key] = value; }); |
49 return result; | 50 return result; |
50 } | 51 } |
51 | 52 |
52 | 53 |
53 Iterable<K> get keys => _keys; | 54 Iterable<K> get keys => _keys; |
54 | 55 |
55 Iterable<V> get values => _values; | 56 Iterable<V> get values => _values; |
56 | 57 |
57 int get length { | 58 int get length { |
58 if (observeReads) notifyRead(this, ChangeRecord.FIELD, 'length'); | 59 if (observeReads) notifyRead(this, ChangeRecord.FIELD, 'length'); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 throw new StateError('keys and values should be the same length'); | 202 throw new StateError('keys and values should be the same length'); |
202 } | 203 } |
203 return _hasNext = moreValues; | 204 return _hasNext = moreValues; |
204 } | 205 } |
205 | 206 |
206 V get current { | 207 V get current { |
207 if (observeReads && _hasNext) _map._notifyReadKey(_keys.current); | 208 if (observeReads && _hasNext) _map._notifyReadKey(_keys.current); |
208 return _values.current; | 209 return _values.current; |
209 } | 210 } |
210 } | 211 } |
OLD | NEW |