putAllAndUpdateExisting method
Future<void>
putAllAndUpdateExisting(
- Map<
TKey, TVal> newValues, - void mutateExisting(
- TKey key,
- TVal mutateMe,
- TVal newValueReadOnly
override
Same as putAll, but instead of removing old objects, changes (mutates) their values to new values
Implementation
@override
Future<void> putAllAndUpdateExisting(
Map<TKey, TVal> newValues,
void Function(TKey key, TVal mutateMe, TVal newValueReadOnly)
mutateExisting,
) async {
final actualNewValue = <TKey, TVal>{};
for (var item in newValues.entries) {
final key = item.key;
final val = item.value;
if (!dataBox.containsKey(key)) {
actualNewValue[key] = val;
} else {
final oldVal = await getValueById(key);
mutateExisting(key, oldVal!, val);
actualNewValue[key] = oldVal;
}
}
await putAll(actualNewValue);
}