getOrCreate<T> method
HopeController<T>
getOrCreate<T>({
- required List queryKey,
- required Future<
T> fetcher(- dynamic pageParam
- required HopeOptions options,
- dynamic getNextPageParam(
- T lastResult
Returns existing controller or creates a new one for this key. Increments the reference count every time a widget subscribes.
Implementation
HopeController<T> getOrCreate<T>({
required List<dynamic> queryKey,
required Future<T> Function(dynamic pageParam) fetcher,
required HopeOptions options,
dynamic Function(T lastResult)? getNextPageParam,
}) {
final key = _controllerKey(queryKey);
if (_controllers.containsKey(key)) {
_refCounts[key] = (_refCounts[key] ?? 0) + 1;
return _controllers[key] as HopeController<T>;
}
final controller = HopeController<T>(
queryKey: queryKey,
fetcher: fetcher,
options: options,
cache: _cache,
getNextPageParam: getNextPageParam,
);
_controllers[key] = controller;
_refCounts[key] = 1;
return controller;
}