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

Unified Diff: pkg/observe/lib/src/observable_list.dart

Issue 132403010: big update to observe, template_binding, polymer (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: pkg/observe/lib/src/observable_list.dart
diff --git a/pkg/observe/lib/src/observable_list.dart b/pkg/observe/lib/src/observable_list.dart
index be25afa61d4e5dc2f780bc287e8fa9342ca5a295..f7052ff22234fb09a804fee8f8f1495f3e997865 100644
--- a/pkg/observe/lib/src/observable_list.dart
+++ b/pkg/observe/lib/src/observable_list.dart
@@ -255,12 +255,17 @@ class ObservableList<E> extends ListBase<E> with ChangeNotifier {
notifyPropertyChange(#isNotEmpty, oldValue != 0, newValue != 0);
}
+ void discardListChages() {
+ // Leave _listRecords set so we don't schedule another delivery.
+ if (_listRecords != null) _listRecords = [];
+ }
+
bool deliverListChanges() {
if (_listRecords == null) return false;
var records = projectListSplices(this, _listRecords);
_listRecords = null;
- if (_hasListObservers) {
+ if (_hasListObservers && !records.isEmpty) {
_listChanges.add(new UnmodifiableListView<ListChangeRecord>(records));
return true;
}
@@ -284,4 +289,24 @@ class ObservableList<E> extends ListBase<E> with ChangeNotifier {
static List<ListChangeRecord> calculateChangeRecords(
List<Object> oldValue, List<Object> newValue) =>
calcSplices(newValue, 0, newValue.length, oldValue, 0, oldValue.length);
+
+ /**
+ * Updates the [previous] list using the change [records]. For added items,
+ * the [current] list is used to find the current value.
+ */
+ static void applyChangeRecords(List<Object> previous, List<Object> current,
+ List<ListChangeRecord> changeRecords) {
+
+ if (identical(previous, current)) {
+ throw new ArgumentError("can't use same list for previous and current");
+ }
+
+ for (var change in changeRecords) {
+ int addEnd = change.index + change.addedCount;
+ int removeEnd = change.index + change.removed.length;
+
+ var addedItems = current.getRange(change.index, addEnd);
+ previous.replaceRange(change.index, removeEnd, addedItems);
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698