updateBy<M> method
Implementation
FutureOr<M?> updateBy<M>(
FutureOr<M> Function(M old) updater, {
String tag = '',
Function(Object e, StackTrace s)? onError,
int slowlyMs = 100,
Object? debounceTag,
Object? throttleTag,
Object? mutexTag,
OnLogging<M>? logging,
}) {
final rst = update(
(old) {
final r = updater(old.modelValue<M>(tag));
if (r is Future<M>) {
return r.then(
(r) => old.copyWith({
FrUnion.modelKey<M>(tag: tag): r as FrUnionModel,
}),
);
} else {
return old.copyWith({
FrUnion.modelKey<M>(tag: tag): r as FrUnionModel,
});
}
},
onError: onError,
slowlyMs: slowlyMs,
debounceTag: debounceTag,
throttleTag: throttleTag,
mutexTag: mutexTag,
logging:
logging == null
? null
: (previous, current) => logging.call(
previous.modelValue<M>(tag),
current.modelValue<M>(tag),
),
);
if (rst is Future<FrUnion>) {
return rst.then((r) => r.modelValue<M>(tag));
} else if (rst is FrUnion) {
return rst.modelValue<M>(tag);
} else {
return null;
}
}