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

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

Issue 11412086: Make 'where' lazy. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: FilteredIterable/Iterator -> WhereIterable/Iterator. Created 8 years, 1 month 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) 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 part 'ChangeEvent.dart'; 7 part 'ChangeEvent.dart';
8 part 'EventBatch.dart'; 8 part 'EventBatch.dart';
9 9
10 /** 10 /**
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 return true; 68 return true;
69 } 69 }
70 70
71 return false; 71 return false;
72 } 72 }
73 73
74 bool removeChangeListener(ChangeListener listener) { 74 bool removeChangeListener(ChangeListener listener) {
75 // TODO(rnystrom): This is awkward without List.remove(e). 75 // TODO(rnystrom): This is awkward without List.remove(e).
76 if (listeners.indexOf(listener, 0) != -1) { 76 if (listeners.indexOf(listener, 0) != -1) {
77 bool found = false; 77 bool found = false;
78 listeners = listeners.where((e) => found || !(found = (e == listener))); 78 listeners = listeners
79 .where((e) => found || !(found = (e == listener)))
80 .toList();
79 return true; 81 return true;
80 } else { 82 } else {
81 return false; 83 return false;
82 } 84 }
83 } 85 }
84 86
85 void recordPropertyUpdate(String propertyName, newValue, oldValue) { 87 void recordPropertyUpdate(String propertyName, newValue, oldValue) {
86 recordEvent(new ChangeEvent.property( 88 recordEvent(new ChangeEvent.property(
87 this, propertyName, newValue, oldValue)); 89 this, propertyName, newValue, oldValue));
88 } 90 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 196
195 T removeAt(int index) { 197 T removeAt(int index) {
196 int i = 0; 198 int i = 0;
197 T found = null; 199 T found = null;
198 _internal = _internal.where(bool _(element) { 200 _internal = _internal.where(bool _(element) {
199 if (i++ == index) { 201 if (i++ == index) {
200 found = element; 202 found = element;
201 return false; 203 return false;
202 } 204 }
203 return true; 205 return true;
204 }); 206 }).toList();
205 if (found != null) { 207 if (found != null) {
206 recordListRemove(index, found); 208 recordListRemove(index, found);
207 } 209 }
208 return found; 210 return found;
209 } 211 }
210 212
211 int indexOf(T element, [int start = 0]) { 213 int indexOf(T element, [int start = 0]) {
212 return _internal.indexOf(element, start); 214 return _internal.indexOf(element, start);
213 } 215 }
214 216
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 } 255 }
254 256
255 List getRange(int start, int length) { 257 List getRange(int start, int length) {
256 throw new UnimplementedError(); 258 throw new UnimplementedError();
257 } 259 }
258 260
259 // Iterable<T>: 261 // Iterable<T>:
260 Iterator<T> iterator() => _internal.iterator(); 262 Iterator<T> iterator() => _internal.iterator();
261 263
262 // Collection<T>: 264 // Collection<T>:
263 Collection<T> where(bool f(T element)) => _internal.where(f); 265 Iterable<T> where(bool f(T element)) => _internal.where(f);
264 Iterable mappedBy(f(T element)) => _internal.mappedBy(f); 266 Iterable mappedBy(f(T element)) => _internal.mappedBy(f);
265 bool every(bool f(T element)) => _internal.every(f); 267 bool every(bool f(T element)) => _internal.every(f);
266 bool some(bool f(T element)) => _internal.some(f); 268 bool some(bool f(T element)) => _internal.some(f);
267 void forEach(void f(T element)) { _internal.forEach(f); } 269 void forEach(void f(T element)) { _internal.forEach(f); }
268 bool get isEmpty => length == 0; 270 bool get isEmpty => length == 0;
269 } 271 }
270 272
271 // TODO(jmesserly): is this too granular? Other similar systems make whole 273 // TODO(jmesserly): is this too granular? Other similar systems make whole
272 // classes observable instead of individual fields. The memory cost of having 274 // classes observable instead of individual fields. The memory cost of having
273 // every field effectively boxed, plus having a listeners list is likely too 275 // every field effectively boxed, plus having a listeners list is likely too
(...skipping 11 matching lines...) Expand all
285 // Only fire on an actual change. 287 // Only fire on an actual change.
286 if (!identical(newValue, _value)) { 288 if (!identical(newValue, _value)) {
287 final oldValue = _value; 289 final oldValue = _value;
288 _value = newValue; 290 _value = newValue;
289 recordPropertyUpdate("value", newValue, oldValue); 291 recordPropertyUpdate("value", newValue, oldValue);
290 } 292 }
291 } 293 }
292 294
293 T _value; 295 T _value;
294 } 296 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698