updateRaw method

FutureOr<T?> updateRaw(
  1. FutureOr<T?> update(
    1. T old
    ), {
  2. dynamic onError(
    1. Object e,
    2. StackTrace s
    )?,
  3. int slowlyMs = 100,
  4. Object? debounceTag,
  5. Object? throttleTag,
  6. dynamic ignoreSkipError = true,
})

for advance user you can sync update value, and get the return value update if return value, will call put if return null, will not call put/putError onError if set null,will call putError if set function value, will not call putError, you can invoke putError manually slowlyMs if set <=0 value, will ignore debounce/throttleTag debounceTag enable debounce, require unique within the VM scope throttleTag enable throttle, require unique within the VM scope ignoreSkipError ref runCatching.ignoreSkipError

Implementation

FutureOr<T?> updateRaw(
  FutureOr<T?> Function(T old) update, {
  Function(Object e, StackTrace s)? onError,
  int slowlyMs = 100,
  Object? debounceTag,
  Object? throttleTag,
  ignoreSkipError = true,
}) async {
  if (slowlyMs > 0) {
    if (debounceTag != null) {
      /// debounce
      final deFunc = await slowly.debounce(
        debounceTag,
        update,
        duration: Duration(milliseconds: slowlyMs),
      );
      if (deFunc is! FutureOr<T> Function(T)) return null;
      update = deFunc;
    } else if (throttleTag != null) {
      /// throttle
      final thFunc = slowly.throttle(
        throttleTag,
        update,
        duration: Duration(milliseconds: slowlyMs),
      );
      if (thFunc is! FutureOr<T> Function(T)) return null;
      update = thFunc;
    }
  }
  return await runCatching<T?>(
    () => update(value),
    onSuccess: (r) => r != null ? put(r) : null,
    onFailure: (e, s) => (onError ?? putError).call(e, s),
    ignoreSkipError: ignoreSkipError,
  );
}