update method
Updates the value for the given key.
If key is present, updates its value by calling update with the
current value. If key is not present and ifAbsent is provided,
adds the key with the value returned by ifAbsent.
Notifies subscribers after the update.
Implementation
@override
V update(K key, V Function(V value) update, {V Function()? ifAbsent}) {
if (peek.containsKey(key)) {
final oldValue = peek[key];
final newValue = peek[key] = update(oldValue as V);
if (oldValue != newValue) {
notify(true);
}
return newValue;
}
if (ifAbsent != null) {
final result = peek[key] = ifAbsent();
notify(true);
return result;
}
throw ArgumentError.value(key, "key", "Key not in map.");
}