interceptState method

SnapState<T>? interceptState(
  1. SnapState<T> snap,
  2. StateInterceptor<T>? stateInterceptor
)

Implementation

SnapState<T>? interceptState(
  SnapState<T> snap,
  StateInterceptor<T>? stateInterceptor,
) {
  final oldSnap = snap.oldSnapState!;
  var newSnap = stateInterceptor?.call(oldSnap, snap);
  newSnap = stateInterceptorGlobal?.call(oldSnap, newSnap ?? snap) ?? newSnap;

  newSnap ??= snap;
  // if (snap is SkipSnapState) {
  //   return null;
  // }
  if (newSnap._isImmutable && oldSnap.hashCode == newSnap.hashCode) {
    return null;
  }
  if (!snap.isWaiting && newSnap.isWaiting) {
    return newSnap.copyWith(infoMessage: kStopWaiting);
  }

  if (newSnap.hasError) {
    // if (_snapState.hasError &&
    //     newSnap.snapError!.error == _snapState.snapError?.error) {
    //   return null;
    // }
  } else if (newSnap.hasData) {
    if (newSnap._isImmutable == true &&
        newSnap == _snapState &&
        _snapState._infoMessage != kRefreshMessage) {
      return null;
    }
  }
  return newSnap;
}