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

Side by Side Diff: samples/swarm/swarm_ui_lib/observable/observable.dart

Issue 12391046: Add List.asMap(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 9 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
« no previous file with comments | « runtime/lib/growable_array.dart ('k') | sdk/lib/_collection_dev/list.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 observable; 5 library observable;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 part 'ChangeEvent.dart'; 9 part 'ChangeEvent.dart';
10 part 'EventBatch.dart'; 10 part 'EventBatch.dart';
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 } 299 }
300 T lastMatching(bool test(T value), {T orElse()}) { 300 T lastMatching(bool test(T value), {T orElse()}) {
301 return _internal.lastMatching(test, orElse: orElse); 301 return _internal.lastMatching(test, orElse: orElse);
302 } 302 }
303 T singleMatching(bool test(T value)) { 303 T singleMatching(bool test(T value)) {
304 return _internal.singleMatching(test); 304 return _internal.singleMatching(test);
305 } 305 }
306 T elementAt(int index) { 306 T elementAt(int index) {
307 return _internal.elementAt(index); 307 return _internal.elementAt(index);
308 } 308 }
309 Map<int, T> asMap() {
310 return IterableMixinWorkaround.asMapList(_internal);
311 }
309 312
310 bool get isEmpty => length == 0; 313 bool get isEmpty => length == 0;
311 } 314 }
312 315
313 // TODO(jmesserly): is this too granular? Other similar systems make whole 316 // TODO(jmesserly): is this too granular? Other similar systems make whole
314 // classes observable instead of individual fields. The memory cost of having 317 // classes observable instead of individual fields. The memory cost of having
315 // every field effectively boxed, plus having a listeners list is likely too 318 // every field effectively boxed, plus having a listeners list is likely too
316 // much. Also, making a value observable necessitates adding ".value" to lots 319 // much. Also, making a value observable necessitates adding ".value" to lots
317 // of places, and constructing all fields with the verbose 320 // of places, and constructing all fields with the verbose
318 // "new ObservableValue<DataType>(myValue)". 321 // "new ObservableValue<DataType>(myValue)".
319 /** A wrapper around a single value whose change can be observed. */ 322 /** A wrapper around a single value whose change can be observed. */
320 class ObservableValue<T> extends AbstractObservable { 323 class ObservableValue<T> extends AbstractObservable {
321 ObservableValue(T value, [Observable parent = null]) 324 ObservableValue(T value, [Observable parent = null])
322 : super(parent), _value = value; 325 : super(parent), _value = value;
323 326
324 T get value => _value; 327 T get value => _value;
325 328
326 void set value(T newValue) { 329 void set value(T newValue) {
327 // Only fire on an actual change. 330 // Only fire on an actual change.
328 if (!identical(newValue, _value)) { 331 if (!identical(newValue, _value)) {
329 final oldValue = _value; 332 final oldValue = _value;
330 _value = newValue; 333 _value = newValue;
331 recordPropertyUpdate("value", newValue, oldValue); 334 recordPropertyUpdate("value", newValue, oldValue);
332 } 335 }
333 } 336 }
334 337
335 T _value; 338 T _value;
336 } 339 }
OLDNEW
« no previous file with comments | « runtime/lib/growable_array.dart ('k') | sdk/lib/_collection_dev/list.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698