mockableCreator property

  1. @override
Object? Function() get mockableCreator
override

Implementation

@override
Object? Function() get mockableCreator {
  if (cachedCreatorMocks.last != null) {
    isWaitingToInitialize = true;
    return super.mockableCreator;
  }
  return () async {
    final List<T> cache = super.mockableCreator() as List<T>;
    if (cache.isNotEmpty) {
      await _init();
      onMiddleCRUD(const SnapState.none().copyToHasData(cache));
      return cache;
    }
    onMiddleCRUD(const SnapState.none().copyToIsWaiting());
    await _init();
    // crud;
    if (readOnInitialization) {
      try {
        final l = await getRepoAs<ICRUD<T, P>>().read(param?.call());
        onMiddleCRUD(const SnapState.none().copyToHasData(l));
        return [...l];
      } catch (e, s) {
        onMiddleCRUD(
          const SnapState.none().copyWith(
            status: StateStatus.hasError,
            error: SnapError(
              error: e,
              stackTrace: s,
              refresher: refresh,
            ),
            infoMessage: '',
          ),
        );
        rethrow;
      }
    } else {
      onMiddleCRUD(const SnapState.none().copyToHasData(cache));
      return cache;
    }
  };
}