diff --git a/packages/fl_query/lib/src/base_operation.dart b/packages/fl_query/lib/src/base_operation.dart index 03978d8..1f83b58 100644 --- a/packages/fl_query/lib/src/base_operation.dart +++ b/packages/fl_query/lib/src/base_operation.dart @@ -1,4 +1,3 @@ -import 'package:fl_query/src/query_bowl.dart'; import 'package:flutter/widgets.dart'; abstract class BaseOperation extends ChangeNotifier { @@ -27,13 +26,10 @@ abstract class BaseOperation extends ChangeNotifier { /// storage/cache Set> _mounts = {}; - final QueryBowl queryBowl; - BaseOperation({ required this.cacheTime, required this.retries, required this.retryDelay, - required this.queryBowl, this.data, }) : updatedAt = DateTime.now(); diff --git a/packages/fl_query/lib/src/base_query.dart b/packages/fl_query/lib/src/base_query.dart index f20328a..b81967f 100644 --- a/packages/fl_query/lib/src/base_query.dart +++ b/packages/fl_query/lib/src/base_query.dart @@ -52,7 +52,6 @@ abstract class BaseQuery required Outside externalData, required super.retries, required super.retryDelay, - required super.queryBowl, required this.status, this.refetchOnMount, this.refetchOnReconnect, diff --git a/packages/fl_query/lib/src/infinite_query.dart b/packages/fl_query/lib/src/infinite_query.dart index 342c057..1f3359f 100644 --- a/packages/fl_query/lib/src/infinite_query.dart +++ b/packages/fl_query/lib/src/infinite_query.dart @@ -20,7 +20,7 @@ typedef InfiniteQueryListeners = FutureOr typedef InfiniteQueryPageParamFunction - = FutureOr Function(T lastPage, PageParam lastParam); + = FutureOr Function(T lastPage, PageParam lastParam); class InfiniteQuery extends BaseQuery, Outside, Map> { @@ -54,7 +54,6 @@ class InfiniteQuery required super.externalData, required super.retries, required super.retryDelay, - required super.queryBowl, required super.status, required PageParam initialParam, super.refetchOnMount, @@ -73,7 +72,6 @@ class InfiniteQuery InfiniteQuery.fromOptions( InfiniteQueryJob options, { - required super.queryBowl, required Outside externalData, InfiniteQueryListeners? onData, InfiniteQueryListeners? onError, diff --git a/packages/fl_query/lib/src/mutation.dart b/packages/fl_query/lib/src/mutation.dart index 040aa0b..0353e45 100644 --- a/packages/fl_query/lib/src/mutation.dart +++ b/packages/fl_query/lib/src/mutation.dart @@ -50,7 +50,6 @@ class Mutation extends BaseOperation required this.task, required super.retries, required super.retryDelay, - required super.queryBowl, required Duration cacheTime, MutationListener? onData, MutationListener? onError, @@ -67,7 +66,6 @@ class Mutation extends BaseOperation MutationListener? onData, MutationListener? onError, MutationListenerReturnable? onMutate, - required super.queryBowl, }) : mutationKey = options.mutationKey, task = options.task, status = MutationStatus.idle, diff --git a/packages/fl_query/lib/src/query.dart b/packages/fl_query/lib/src/query.dart index 55a321b..8fb6722 100644 --- a/packages/fl_query/lib/src/query.dart +++ b/packages/fl_query/lib/src/query.dart @@ -50,7 +50,6 @@ class Query extends BaseQuery { required super.externalData, required super.retries, required super.retryDelay, - required super.queryBowl, required super.status, super.refetchOnMount, super.refetchOnReconnect, @@ -65,7 +64,6 @@ class Query extends BaseQuery { Query.fromOptions( QueryJob options, { - required super.queryBowl, required Outside externalData, T? previousData, QueryListener? onData, diff --git a/packages/fl_query/lib/src/query_bowl.dart b/packages/fl_query/lib/src/query_bowl.dart index b343deb..e84cdf8 100644 --- a/packages/fl_query/lib/src/query_bowl.dart +++ b/packages/fl_query/lib/src/query_bowl.dart @@ -264,7 +264,6 @@ class QueryBowl { options, externalData: externalData, previousData: previousData, - queryBowl: this, ); query.updateDefaultOptions( cacheTime: cache.cacheTime, @@ -284,7 +283,6 @@ class QueryBowl { final infiniteQuery = InfiniteQuery.fromOptions( options, externalData: externalData, - queryBowl: this, ); infiniteQuery.updateDefaultOptions( cacheTime: cache.cacheTime, @@ -400,7 +398,6 @@ class QueryBowl { } else { final mutation = Mutation.fromOptions( mutationJob, - queryBowl: this, ); if (onData != null) mutation.addDataListener(onData); if (onError != null) mutation.addErrorListener(onError); diff --git a/packages/fl_query/test/query_test.dart b/packages/fl_query/test/query_test.dart index 5823426..5fd0333 100644 --- a/packages/fl_query/test/query_test.dart +++ b/packages/fl_query/test/query_test.dart @@ -24,10 +24,8 @@ void main() { // for testing query without external data late Query query; late MockQueryJobVoidObject queryJob; - late MockQueryBowl queryBowl; setUp(() { queryJob = MockQueryJobVoidObject(); - queryBowl = MockQueryBowl(); when(queryJob.queryKey).thenReturn("test"); when(queryJob.task).thenAnswer( (_) => @@ -36,7 +34,6 @@ void main() { query = Query.fromOptions( queryJob, externalData: null, - queryBowl: queryBowl, ); }); @@ -86,7 +83,6 @@ void main() { query = Query.fromOptions( queryJob, externalData: null, - queryBowl: queryBowl, ); await Future.delayed(Duration(milliseconds: 100)); @@ -119,7 +115,6 @@ void main() { query = Query.fromOptions( queryJob, externalData: null, - queryBowl: queryBowl, ); await query.fetch(); @@ -150,7 +145,6 @@ void main() { query = Query.fromOptions( queryJob, externalData: null, - queryBowl: queryBowl, ); int count = 0; query.addErrorListener((_) { @@ -165,7 +159,6 @@ void main() { query = Query.fromOptions( queryJob, externalData: null, - queryBowl: queryBowl, ); expect(query.isStale, isFalse); await Future.delayed(Duration(milliseconds: 300)); @@ -190,7 +183,6 @@ void main() { query = Query.fromOptions( queryJob, externalData: null, - queryBowl: queryBowl, ); final data = await query.fetch(); @@ -210,7 +202,6 @@ void main() { query = Query.fromOptions( queryJob, externalData: null, - queryBowl: queryBowl, ); final data = await query.fetch(); query.invalidate(); @@ -237,7 +228,6 @@ void main() { query = Query.fromOptions( queryJob, externalData: null, - queryBowl: queryBowl, ); final data = await query.fetch(); query.invalidate(); diff --git a/packages/fl_query_hooks/example/.flutter-plugins-dependencies b/packages/fl_query_hooks/example/.flutter-plugins-dependencies index 80cd7ee..42d8f2b 100644 --- a/packages/fl_query_hooks/example/.flutter-plugins-dependencies +++ b/packages/fl_query_hooks/example/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.6/","native_build":true,"dependencies":[]}],"android":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.6/","native_build":true,"dependencies":[]}],"macos":[{"name":"connectivity_plus_macos","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_macos-1.2.4/","native_build":true,"dependencies":[]}],"linux":[{"name":"connectivity_plus_linux","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_linux-1.3.1/","native_build":false,"dependencies":[]}],"windows":[{"name":"connectivity_plus_windows","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_windows-1.2.2/","native_build":true,"dependencies":[]}],"web":[{"name":"connectivity_plus_web","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_web-1.2.3/","dependencies":[]}]},"dependencyGraph":[{"name":"connectivity_plus","dependencies":["connectivity_plus_linux","connectivity_plus_macos","connectivity_plus_web","connectivity_plus_windows"]},{"name":"connectivity_plus_linux","dependencies":[]},{"name":"connectivity_plus_macos","dependencies":[]},{"name":"connectivity_plus_web","dependencies":[]},{"name":"connectivity_plus_windows","dependencies":[]}],"date_created":"2022-09-22 21:28:31.234632","version":"3.3.0"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.6/","native_build":true,"dependencies":[]}],"android":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.6/","native_build":true,"dependencies":[]}],"macos":[{"name":"connectivity_plus_macos","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_macos-1.2.4/","native_build":true,"dependencies":[]}],"linux":[{"name":"connectivity_plus_linux","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_linux-1.3.1/","native_build":false,"dependencies":[]}],"windows":[{"name":"connectivity_plus_windows","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_windows-1.2.2/","native_build":true,"dependencies":[]}],"web":[{"name":"connectivity_plus_web","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_web-1.2.3/","dependencies":[]}]},"dependencyGraph":[{"name":"connectivity_plus","dependencies":["connectivity_plus_linux","connectivity_plus_macos","connectivity_plus_web","connectivity_plus_windows"]},{"name":"connectivity_plus_linux","dependencies":[]},{"name":"connectivity_plus_macos","dependencies":[]},{"name":"connectivity_plus_web","dependencies":[]},{"name":"connectivity_plus_windows","dependencies":[]}],"date_created":"2022-09-26 14:46:50.585900","version":"3.3.0"} \ No newline at end of file diff --git a/packages/fl_query_hooks/lib/src/use_infinite_query.dart b/packages/fl_query_hooks/lib/src/use_infinite_query.dart index 7e5ad61..d6756fe 100644 --- a/packages/fl_query_hooks/lib/src/use_infinite_query.dart +++ b/packages/fl_query_hooks/lib/src/use_infinite_query.dart @@ -24,10 +24,15 @@ InfiniteQuery final QueryBowl queryBowl = QueryBowl.of(context); final ValueKey uKey = useMemoized(() => ValueKey(uuid.v4()), []); final infiniteQuery = useRef( - InfiniteQuery.fromOptions( - job, - externalData: externalData, - queryBowl: queryBowl, + useMemoized( + () => queryBowl.addInfiniteQuery( + job, + externalData: externalData, + key: uKey, + onData: onData, + onError: onError, + ), + [], ), ); @@ -129,5 +134,5 @@ InfiniteQuery return null; }); - return queryBowl.getInfiniteQuery(job.queryKey) ?? infiniteQuery.value; + return infiniteQuery.value; } diff --git a/packages/fl_query_hooks/lib/src/use_mutation.dart b/packages/fl_query_hooks/lib/src/use_mutation.dart index 4ab6dc9..e614b3e 100644 --- a/packages/fl_query_hooks/lib/src/use_mutation.dart +++ b/packages/fl_query_hooks/lib/src/use_mutation.dart @@ -24,8 +24,18 @@ Mutation useMutation({ final update = useForceUpdate(); final QueryBowl queryBowl = QueryBowl.of(context); final ValueKey uKey = useMemoized(() => ValueKey(uuid.v4()), []); - final mutation = - useRef(Mutation.fromOptions(job, queryBowl: queryBowl)); + final mutation = useRef( + useMemoized( + () => queryBowl.addMutation( + job, + onData: onData, + onError: onError, + onMutate: onMutate, + key: uKey, + ), + [], + ), + ); final init = useCallback(() { mutation.value = queryBowl.addMutation( @@ -85,5 +95,5 @@ Mutation useMutation({ return null; }); - return queryBowl.getMutation(job.mutationKey) ?? mutation.value; + return mutation.value; } diff --git a/packages/fl_query_hooks/lib/src/use_query.dart b/packages/fl_query_hooks/lib/src/use_query.dart index d3d08ae..2b29450 100644 --- a/packages/fl_query_hooks/lib/src/use_query.dart +++ b/packages/fl_query_hooks/lib/src/use_query.dart @@ -23,10 +23,15 @@ Query useQuery({ final QueryBowl queryBowl = QueryBowl.of(context); final ValueKey uKey = useMemoized(() => ValueKey(uuid.v4()), []); final query = useRef( - Query.fromOptions( - job, - externalData: externalData, - queryBowl: queryBowl, + useMemoized( + () => queryBowl.addQuery( + job, + externalData: externalData, + key: uKey, + onData: onData, + onError: onError, + ), + [], ), ); @@ -125,5 +130,5 @@ Query useQuery({ return null; }); - return queryBowl.getQuery(job.queryKey) ?? query.value; + return query.value; }