refactor(QueryBowl): query bowl logic as a separate class instead of a stateful widget

feat: add QueryCache class for storing, updating, removing all the query/mutation/infiniteQueries
refactor(test): update tests according to new query bowl refactor
refactor(fl_query_hooks): update the hooks according to new query bowl refactor
This commit is contained in:
Kingkor Roy Tirtho
2022-09-22 22:03:28 +06:00
parent f435f101c4
commit 2b835505a3
22 changed files with 804 additions and 733 deletions
+14 -2
View File
@@ -17,6 +17,8 @@ Query<T, Outside> useQuery<T extends Object, Outside>({
QueryListener<dynamic>? onError,
List<Object?>? keys,
}) {
final mounted = useIsMounted();
final update = useForceUpdate();
final context = useContext();
final QueryBowl queryBowl = QueryBowl.of(context);
final ValueKey<String> uKey = useMemoized(() => ValueKey(uuid.v4()), []);
@@ -42,6 +44,7 @@ Query<T, Outside> useQuery<T extends Object, Outside>({
onData: onData,
onError: onError,
);
update();
final hasExternalDataChanged = query.value.externalData != null &&
query.value.prevUsedExternalData != null &&
!isShallowEqual(
@@ -60,7 +63,16 @@ Query<T, Outside> useQuery<T extends Object, Outside>({
}, [query.value, onData, onError, uKey]);
useEffect(() {
init();
WidgetsBinding.instance.addPostFrameCallback((_) {
init();
QueryBowl.of(context).onQueriesUpdate<T, Outside>(
(newQuery) {
if (newQuery.queryKey != job.queryKey || !mounted()) return;
query.value = newQuery;
update();
},
);
});
return disposeQuery;
}, []);
@@ -113,5 +125,5 @@ Query<T, Outside> useQuery<T extends Object, Outside>({
return null;
});
return queryBowl.getQuery<T, Outside>(job.queryKey) ?? query.value;
return query.value;
}