isFetching method
Returns whether queries are currently fetching.
Can optionally be filtered by:
queryKey: Checks if the specific query matching the key is currently fetching.tag: Checks if any query with the given tag is currently fetching.predicate: Checks if any query matching the custom predicate is currently fetching.
If no filters are provided, returns whether ANY query in the application is currently fetching (ZenQuery.anyFetching).
Implementation
bool isFetching({
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;
}
if (tag != null) {
final queries = getQueriesByTag(tag);
return queries.any((q) => q.isFetching);
}
if (predicate != null) {
return _queries.values
.where((q) => !q.isDisposed)
.any((q) => predicate(q) && q.isFetching);
}
return ZenQuery.anyFetching;
}