isFetchingCount method

int isFetchingCount({
  1. Object? queryKey,
  2. String? tag,
  3. bool predicate(
    1. ZenQuery query
    )?,
})

Returns the count of queries currently fetching (optionally filtered by queryKey, tag, or predicate).

Implementation

int isFetchingCount({
  Object? queryKey,
  String? tag,
  bool Function(ZenQuery query)? predicate,
}) {
  if (queryKey != null) {
    final normalizedKey = QueryKey.normalize(queryKey);
    final query = _queries[normalizedKey];
    return (query != null && !query.isDisposed && query.isFetching) ? 1 : 0;
  }

  if (tag != null) {
    final queries = getQueriesByTag(tag);
    return queries.where((q) => q.isFetching).length;
  }

  if (predicate != null) {
    return _queries.values
        .where((q) => !q.isDisposed)
        .where((q) => predicate(q) && q.isFetching)
        .length;
  }

  return ZenQuery.activeFetches.value;
}