refactor: more convenient ways customizing config
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import 'package:fl_query/src/collections/refresh_config.dart';
|
||||
import 'package:fl_query/src/collections/retry_config.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@immutable
|
||||
abstract class DefaultConstants {
|
||||
static const RetryConfig retryConfig = RetryConfig(
|
||||
maxRetries: 3,
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
import 'package:fl_query/src/collections/default_configs.dart';
|
||||
import 'package:fl_query/src/core/client.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class RefreshConfig {
|
||||
final Duration staleDuration;
|
||||
final Duration refreshInterval;
|
||||
@@ -10,4 +14,48 @@ class RefreshConfig {
|
||||
required this.refreshOnMount,
|
||||
required this.refreshOnQueryFnChange,
|
||||
});
|
||||
|
||||
factory RefreshConfig.withDefaults(
|
||||
BuildContext context, {
|
||||
Duration? staleDuration,
|
||||
Duration? refreshInterval,
|
||||
bool? refreshOnMount,
|
||||
bool? refreshOnQueryFnChange,
|
||||
}) {
|
||||
return QueryClient.of(context).refreshConfig.copyWith(
|
||||
staleDuration: staleDuration,
|
||||
refreshInterval: refreshInterval,
|
||||
refreshOnMount: refreshOnMount,
|
||||
refreshOnQueryFnChange: refreshOnQueryFnChange,
|
||||
);
|
||||
}
|
||||
|
||||
factory RefreshConfig.withConstantDefaults({
|
||||
Duration? staleDuration,
|
||||
Duration? refreshInterval,
|
||||
bool? refreshOnMount,
|
||||
bool? refreshOnQueryFnChange,
|
||||
}) {
|
||||
return DefaultConstants.refreshConfig.copyWith(
|
||||
staleDuration: staleDuration,
|
||||
refreshInterval: refreshInterval,
|
||||
refreshOnMount: refreshOnMount,
|
||||
refreshOnQueryFnChange: refreshOnQueryFnChange,
|
||||
);
|
||||
}
|
||||
|
||||
RefreshConfig copyWith({
|
||||
Duration? staleDuration,
|
||||
Duration? refreshInterval,
|
||||
bool? refreshOnMount,
|
||||
bool? refreshOnQueryFnChange,
|
||||
}) {
|
||||
return RefreshConfig(
|
||||
staleDuration: staleDuration ?? this.staleDuration,
|
||||
refreshInterval: refreshInterval ?? this.refreshInterval,
|
||||
refreshOnMount: refreshOnMount ?? this.refreshOnMount,
|
||||
refreshOnQueryFnChange:
|
||||
refreshOnQueryFnChange ?? this.refreshOnQueryFnChange,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,41 @@
|
||||
import 'package:fl_query/src/collections/default_configs.dart';
|
||||
import 'package:fl_query/src/core/client.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class RetryConfig {
|
||||
final int maxRetries;
|
||||
final Duration retryDelay;
|
||||
|
||||
const RetryConfig({required this.maxRetries, required this.retryDelay});
|
||||
|
||||
factory RetryConfig.withDefaults(
|
||||
BuildContext context, {
|
||||
int? maxRetries,
|
||||
Duration? retryDelay,
|
||||
}) {
|
||||
return QueryClient.of(context).retryConfig.copyWith(
|
||||
maxRetries: maxRetries,
|
||||
retryDelay: retryDelay,
|
||||
);
|
||||
}
|
||||
|
||||
factory RetryConfig.withConstantDefaults({
|
||||
int? maxRetries,
|
||||
Duration? retryDelay,
|
||||
}) {
|
||||
return DefaultConstants.retryConfig.copyWith(
|
||||
maxRetries: maxRetries,
|
||||
retryDelay: retryDelay,
|
||||
);
|
||||
}
|
||||
|
||||
RetryConfig copyWith({
|
||||
int? maxRetries,
|
||||
Duration? retryDelay,
|
||||
}) {
|
||||
return RetryConfig(
|
||||
maxRetries: maxRetries ?? this.maxRetries,
|
||||
retryDelay: retryDelay ?? this.retryDelay,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user