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

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

Issue 15263004: Adding isNotEmpty property to collection and string. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix template generation Created 7 years, 7 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/typed_data.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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 return _internal.singleWhere(test); 318 return _internal.singleWhere(test);
319 } 319 }
320 T elementAt(int index) { 320 T elementAt(int index) {
321 return _internal.elementAt(index); 321 return _internal.elementAt(index);
322 } 322 }
323 Map<int, T> asMap() { 323 Map<int, T> asMap() {
324 return _internal.asMap(); 324 return _internal.asMap();
325 } 325 }
326 326
327 bool get isEmpty => length == 0; 327 bool get isEmpty => length == 0;
328
329 bool get isNotEmpty => !isEmpty;
328 } 330 }
329 331
330 // TODO(jmesserly): is this too granular? Other similar systems make whole 332 // TODO(jmesserly): is this too granular? Other similar systems make whole
331 // classes observable instead of individual fields. The memory cost of having 333 // classes observable instead of individual fields. The memory cost of having
332 // every field effectively boxed, plus having a listeners list is likely too 334 // every field effectively boxed, plus having a listeners list is likely too
333 // much. Also, making a value observable necessitates adding ".value" to lots 335 // much. Also, making a value observable necessitates adding ".value" to lots
334 // of places, and constructing all fields with the verbose 336 // of places, and constructing all fields with the verbose
335 // "new ObservableValue<DataType>(myValue)". 337 // "new ObservableValue<DataType>(myValue)".
336 /** A wrapper around a single value whose change can be observed. */ 338 /** A wrapper around a single value whose change can be observed. */
337 class ObservableValue<T> extends AbstractObservable { 339 class ObservableValue<T> extends AbstractObservable {
338 ObservableValue(T value, [Observable parent = null]) 340 ObservableValue(T value, [Observable parent = null])
339 : super(parent), _value = value; 341 : super(parent), _value = value;
340 342
341 T get value => _value; 343 T get value => _value;
342 344
343 void set value(T newValue) { 345 void set value(T newValue) {
344 // Only fire on an actual change. 346 // Only fire on an actual change.
345 if (!identical(newValue, _value)) { 347 if (!identical(newValue, _value)) {
346 final oldValue = _value; 348 final oldValue = _value;
347 _value = newValue; 349 _value = newValue;
348 recordPropertyUpdate("value", newValue, oldValue); 350 recordPropertyUpdate("value", newValue, oldValue);
349 } 351 }
350 } 352 }
351 353
352 T _value; 354 T _value;
353 } 355 }
OLDNEW
« no previous file with comments | « runtime/lib/typed_data.dart ('k') | sdk/lib/_collection_dev/list.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698