applyChangeRecords<E> static method

void applyChangeRecords<E>(
  1. List<Object> previous,
  2. List<Object> current,
  3. List<ListChangeRecord<E>> changeRecords
)

Updates the previous list using the changeRecords. For added items, the current list is used to find the current value.

Implementation

static void applyChangeRecords<E>(List<Object> previous, List<Object> current,
    List<ListChangeRecord<E>> changeRecords) {
  if (identical(previous, current)) {
    throw ArgumentError("can't use same list for previous and current");
  }

  for (var change in changeRecords) {
    var addEnd = change.index + change.addedCount;
    var removeEnd = change.index + change.removed.length;

    var addedItems = current.getRange(change.index, addEnd);
    previous.replaceRange(change.index, removeEnd, addedItems);
  }
}