ZenQuery<T> constructor
ZenQuery<T> ({})
Implementation
ZenQuery({
required Object queryKey,
required this.fetcher,
ZenQueryConfig? config,
this.initialData,
this.scope,
this.autoDispose = true,
bool registerInCache = true,
}) : queryKey = QueryKey.normalize(queryKey), // Normalize on init
config = ZenQueryConfig.defaults.merge(config),
_registerInCache = registerInCache {
// Set initial data if provided
if (initialData != null) {
data.value = initialData;
status.value = ZenQueryStatus.success;
// Don't set _lastFetchTime here - initial data should be considered stale
// so that the first fetch() actually fetches fresh data
_lastFetchTime = null;
}
// Register in cache (scope-aware or global)
if (_registerInCache) {
if (scope != null) {
_registerInScope();
} else {
// Register in global cache (existing behavior)
ZenQueryCache.instance.register(this);
}
}
// Setup background refetch if enabled
_setupBackgroundRefetch();
}