applyChanges<R> method

FutureOr<R> applyChanges<R>(
  1. FutureOr<R> build(
    1. MapDiffs<MKey, Record<ISunnyContact>> changes
    ), {
  2. Map<MKey, Record<ISunnyContact>>? replacement,
})
inherited

Implementation

FutureOr<R> applyChanges<R>(
    FutureOr<R> build(MapDiffs<MKey, Record<V>> changes),
    {Map<MKey, Record<V>>? replacement}) {
  final starting = {..._data};
  final changes =
      MapDiffs<MKey, Record<V>>.builder(starting, replacement: replacement);
  final start = DateTime.now();
  return build(changes).thenOr((result) {
    if (changes.isNotEmpty) {
      log.fine(
          "Applied ${changes.length} changes to $V in ${DateTime.now().difference(start).inMilliseconds}ms");
    }

    /// Some stream combiners don't work unless you emit at least once
    var appliedDiff = MapDiffs<MKey, Record<V>>.ofOperations(
        changes.operations,
        MapDiffArguments(
          starting,
          replacement ?? {..._data},
        ));
    _diffStreamController.add(appliedDiff);
    return result;
  } as R Function(FutureOr<R>?));
}