diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1b80a15 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vscode/dryrun.log +.vscode/configurationCache.log diff --git a/packages/fl_query/lib/src/base_operation.dart b/packages/fl_query/lib/src/base_operation.dart index ad1c3e3..0683b25 100644 --- a/packages/fl_query/lib/src/base_operation.dart +++ b/packages/fl_query/lib/src/base_operation.dart @@ -21,7 +21,6 @@ abstract class BaseOperation extends ChangeNotifier { int retryAttempts = 0; DateTime updatedAt; - @protected bool fetched = false; /// used for keeping track of query activity. If the are no mounts & diff --git a/packages/fl_query/lib/src/mutation.dart b/packages/fl_query/lib/src/mutation.dart index 4652210..5e87fd0 100644 --- a/packages/fl_query/lib/src/mutation.dart +++ b/packages/fl_query/lib/src/mutation.dart @@ -168,4 +168,10 @@ class Mutation extends BaseOperation { bool get isLoading => status == MutationStatus.loading; @override bool get isSuccess => status == MutationStatus.success; + + @override + bool operator ==(other) { + return (other is Mutation && other.mutationKey == mutationKey) || + identical(other, this); + } } diff --git a/packages/fl_query/lib/src/mutation_builder.dart b/packages/fl_query/lib/src/mutation_builder.dart index 1822a2a..e3d8304 100644 --- a/packages/fl_query/lib/src/mutation_builder.dart +++ b/packages/fl_query/lib/src/mutation_builder.dart @@ -51,7 +51,7 @@ class _MutationBuilderState void init([_]) { queryBowl = QueryBowl.of(context); mutation = queryBowl.addMutation( - Mutation.fromOptions(widget.job, queryBowl: queryBowl), + widget.job, onData: widget.onData, onError: widget.onError, onMutate: widget.onMutate, diff --git a/packages/fl_query/lib/src/query.dart b/packages/fl_query/lib/src/query.dart index c79a4ae..b01fe01 100644 --- a/packages/fl_query/lib/src/query.dart +++ b/packages/fl_query/lib/src/query.dart @@ -322,4 +322,10 @@ class Query extends BaseOperation { String toString() { return debugLabel; } + + @override + bool operator ==(other) { + return (other is Query && other.queryKey == queryKey) || + identical(other, this); + } } diff --git a/packages/fl_query/lib/src/query_bowl.dart b/packages/fl_query/lib/src/query_bowl.dart index 9598b06..fb11037 100644 --- a/packages/fl_query/lib/src/query_bowl.dart +++ b/packages/fl_query/lib/src/query_bowl.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:connectivity_plus/connectivity_plus.dart'; +import 'package:fl_query/src/models/mutation_job.dart'; import 'package:fl_query/src/models/query_job.dart'; import 'package:fl_query/src/mutation.dart'; import 'package:fl_query/src/mutation_builder.dart'; @@ -334,23 +335,24 @@ class QueryBowl extends InheritedWidget { /// !⚠️**Warning** only for internal library usage @protected Query addQuery( - Query query, { + QueryJob queryJob, { + required Outside externalData, required ValueKey key, final QueryListener? onData, final QueryListener? onError, }) { final prevQuery = - _queries.firstWhereOrNull((q) => q.queryKey == query.queryKey); + _queries.firstWhereOrNull((q) => q.queryKey == queryJob.queryKey); if (prevQuery is Query) { // run the query if its still not called or if externalData has // changed if (prevQuery.prevUsedExternalData != null && - query.externalData != null && + externalData != null && !isShallowEqual( prevQuery.prevUsedExternalData!, - query.externalData!, + externalData, )) { - prevQuery.setExternalData(query.externalData); + prevQuery.setExternalData(externalData); } prevQuery.mount(key); if (onData != null) prevQuery.onDataListeners.add(onData); @@ -358,6 +360,11 @@ class QueryBowl extends InheritedWidget { // mounting the widget that is using the query in the prevQuery return prevQuery; } + final query = Query.fromOptions( + queryJob, + externalData: externalData, + queryBowl: this, + ); if (onData != null) query.onDataListeners.add(onData); if (onError != null) query.onErrorListeners.add(onError); query.updateDefaultOptions( @@ -375,14 +382,14 @@ class QueryBowl extends InheritedWidget { /// !⚠️**Warning** only for internal library usage @protected Mutation addMutation( - Mutation mutation, { + MutationJob mutationJob, { final MutationListener? onData, final MutationListener? onError, final MutationListener? onMutate, required ValueKey key, }) { final prevMutation = _mutations.firstWhereOrNull( - (prevMutation) => prevMutation.mutationKey == mutation.mutationKey); + (prevMutation) => prevMutation.mutationKey == mutationJob.mutationKey); if (prevMutation != null && prevMutation is Mutation) { if (onData != null) prevMutation.onDataListeners.add(onData); if (onError != null) prevMutation.onErrorListeners.add(onError); @@ -390,6 +397,10 @@ class QueryBowl extends InheritedWidget { prevMutation.mount(key); return prevMutation; } else { + final mutation = Mutation.fromOptions( + mutationJob, + queryBowl: this, + ); if (onData != null) mutation.onDataListeners.add(onData); if (onError != null) mutation.onErrorListeners.add(onError); if (onMutate != null) mutation.onMutateListeners.add(onMutate); diff --git a/packages/fl_query/lib/src/query_builder.dart b/packages/fl_query/lib/src/query_builder.dart index 22f528d..e8e8323 100644 --- a/packages/fl_query/lib/src/query_builder.dart +++ b/packages/fl_query/lib/src/query_builder.dart @@ -46,11 +46,8 @@ class _QueryBuilderState void init([QueryBowl? bowl]) async { bowl ??= QueryBowl.of(context); query = bowl.addQuery( - Query.fromOptions( - widget.job, - externalData: widget.externalData, - queryBowl: QueryBowl.of(context), - ), + widget.job, + externalData: widget.externalData, key: uKey, onData: widget.onData, onError: widget.onError, diff --git a/packages/fl_query_hooks/.flutter-plugins-dependencies b/packages/fl_query_hooks/.flutter-plugins-dependencies index 2f7e5b9..5f13755 100644 --- a/packages/fl_query_hooks/.flutter-plugins-dependencies +++ b/packages/fl_query_hooks/.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.5/","native_build":true,"dependencies":[]}],"android":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.5/","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.2/","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-07-08 04:37:56.711440","version":"3.0.1"} \ 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.5/","native_build":true,"dependencies":[]}],"android":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.5/","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.2/","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-07-12 03:10:11.860962","version":"3.0.1"} \ No newline at end of file diff --git a/packages/fl_query_hooks/lib/src/use_mutation.dart b/packages/fl_query_hooks/lib/src/use_mutation.dart index ded48e2..7267e1d 100644 --- a/packages/fl_query_hooks/lib/src/use_mutation.dart +++ b/packages/fl_query_hooks/lib/src/use_mutation.dart @@ -27,7 +27,7 @@ Mutation useMutation({ final init = useCallback(() { mutation.value = queryBowl.addMutation( - mutation.value, + job, onData: onData, onError: onError, onMutate: onMutate, @@ -55,10 +55,6 @@ Mutation useMutation({ useEffect(() { if (oldJob != null && oldJob.mutationKey != job.mutationKey) { disposeMutation(); - mutation.value = Mutation.fromOptions( - job, - queryBowl: queryBowl, - ); init(); } else { if (oldOnData != onData && oldOnData != null) { diff --git a/packages/fl_query_hooks/lib/src/use_query.dart b/packages/fl_query_hooks/lib/src/use_query.dart index 25a44eb..4461d49 100644 --- a/packages/fl_query_hooks/lib/src/use_query.dart +++ b/packages/fl_query_hooks/lib/src/use_query.dart @@ -33,7 +33,8 @@ Query useQuery({ final init = useCallback(() { query.value = queryBowl.addQuery( - query.value, + job, + externalData: externalData, key: uKey, onData: onData, onError: onError, @@ -46,7 +47,7 @@ Query useQuery({ hasExternalDataChanged ? query.value.refetch() : query.value.fetch(); - }, [queryBowl, query.value, uKey, onData, onError, job]); + }, [queryBowl, query.value, uKey, onData, onError, job, externalData]); final disposeQuery = useCallback(() { query.value.unmount(uKey); @@ -64,11 +65,6 @@ Query useQuery({ final hasOnDataChanged = oldOnData != onData && oldOnData != null; if (oldJob != null && oldJob.queryKey != job.queryKey) { disposeQuery(); - query.value = Query.fromOptions( - job, - externalData: externalData, - queryBowl: queryBowl, - ); init(); } else if (oldExternalData != null && externalData != null &&