Internal API change
now query & mutation share same base class queries are now self-refetchable queryJobs & mutationJobs now support dynamic key allowing dynamic Query/Mutation creation query status & mutation status are now just on point & accurate
This commit is contained in:
@@ -1,17 +1,43 @@
|
||||
import 'package:fl_query/mutation.dart';
|
||||
|
||||
class MutationJob<T extends Object, V> {
|
||||
final String mutationKey;
|
||||
String _mutationKey;
|
||||
MutationTaskFunction<T, V> task;
|
||||
final int? retries;
|
||||
final Duration? retryDelay;
|
||||
final Duration? cacheTime;
|
||||
|
||||
MutationJob({
|
||||
required this.mutationKey,
|
||||
required String mutationKey,
|
||||
required this.task,
|
||||
this.retries,
|
||||
this.retryDelay,
|
||||
this.cacheTime,
|
||||
});
|
||||
}) : _mutationKey = mutationKey;
|
||||
|
||||
String get mutationKey => _mutationKey;
|
||||
|
||||
static MutationJob<T, V> Function(String queryKey)
|
||||
withVariableKey<T extends Object, V>({
|
||||
required MutationTaskFunction<T, V> task,
|
||||
|
||||
/// a extra key joined with mutationKey by a '#'
|
||||
///
|
||||
/// useful for matching a group mutation
|
||||
String? preMutationKey,
|
||||
int? retries,
|
||||
Duration? retryDelay,
|
||||
Duration? cacheTime,
|
||||
}) {
|
||||
return (String mutationKey) {
|
||||
if (preMutationKey != null) mutationKey = "$preMutationKey#$mutationKey";
|
||||
return MutationJob<T, V>(
|
||||
mutationKey: mutationKey,
|
||||
task: task,
|
||||
retries: retries,
|
||||
retryDelay: retryDelay,
|
||||
cacheTime: cacheTime,
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import 'package:fl_query/query.dart';
|
||||
|
||||
class QueryJob<T extends Object, Outside> {
|
||||
// all params
|
||||
final String queryKey;
|
||||
String _queryKey;
|
||||
QueryTaskFunction<T, Outside> task;
|
||||
final int? retries;
|
||||
final Duration? retryDelay;
|
||||
@@ -13,11 +13,14 @@ class QueryJob<T extends Object, Outside> {
|
||||
final bool? enabled;
|
||||
|
||||
// got from global options
|
||||
final Duration? staleTime;
|
||||
final Duration? cacheTime;
|
||||
bool? refetchOnMount;
|
||||
Duration? staleTime;
|
||||
Duration? cacheTime;
|
||||
|
||||
Duration? refetchInterval;
|
||||
|
||||
QueryJob({
|
||||
required this.queryKey,
|
||||
required String queryKey,
|
||||
required this.task,
|
||||
this.retries,
|
||||
this.retryDelay,
|
||||
@@ -25,5 +28,43 @@ class QueryJob<T extends Object, Outside> {
|
||||
this.staleTime,
|
||||
this.cacheTime,
|
||||
this.enabled,
|
||||
});
|
||||
this.refetchInterval,
|
||||
this.refetchOnMount,
|
||||
}) : _queryKey = queryKey;
|
||||
|
||||
String get queryKey => _queryKey;
|
||||
|
||||
static QueryJob<T, Outside> Function(String queryKey)
|
||||
withVariableKey<T extends Object, Outside>({
|
||||
required QueryTaskFunction<T, Outside> task,
|
||||
|
||||
/// a extra key joined with queryKey by a '#'
|
||||
///
|
||||
/// useful for matching a group query
|
||||
String? preQueryKey,
|
||||
int? retries,
|
||||
Duration? retryDelay,
|
||||
T? initialData,
|
||||
Duration? staleTime,
|
||||
Duration? cacheTime,
|
||||
bool? enabled,
|
||||
Duration? refetchInterval,
|
||||
bool? refetchOnMount,
|
||||
}) {
|
||||
return (String queryKey) {
|
||||
if (preQueryKey != null) queryKey = "$preQueryKey#$queryKey";
|
||||
return QueryJob<T, Outside>(
|
||||
queryKey: queryKey,
|
||||
task: task,
|
||||
retries: retries,
|
||||
retryDelay: retryDelay,
|
||||
initialData: initialData,
|
||||
staleTime: staleTime,
|
||||
cacheTime: cacheTime,
|
||||
enabled: enabled,
|
||||
refetchInterval: refetchInterval,
|
||||
refetchOnMount: refetchOnMount,
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user