sync method

Future<ListDiffs<V>> sync(
  1. FutureOr<Iterable<V>?> newItemsFuture, {
  2. bool async = true,
})

Syncs the values of this list with a replacement list, and emits modification events in the form of ListChange

Implementation

Future<ListDiffs<V>> sync(FutureOr<Iterable<V>?> newItemsFuture,
    {bool async = true}) async {
  final SunnyObservableList<V> _items = this;
  final newItems = await newItemsFuture;

  ListDiffs<V> diff;
  if (async) {
    diff = await _items.differencesAsync(
      [...newItems!],
      algorithm: diffAlgorithm ?? ListDiffAlgorithm.myers,
      equality: diffEquality,
      debugName: debugLabel,
    );
  } else {
    diff = _items.differences(
      [...newItems!],
      algorithm: diffAlgorithm ?? ListDiffAlgorithm.myers,
      equality: diffEquality,
    );
  }

  /// Apply patches may do some modification
  applyPatches(diff);
  return diff;
}