fix: refetchOnExternalDataChange isn't working #18
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# This is a generated file; do not edit or check into version control.
|
||||
connectivity_plus=/opt/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.9/
|
||||
connectivity_plus_linux=/opt/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_linux-1.3.1/
|
||||
connectivity_plus_macos=/opt/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_macos-1.2.6/
|
||||
connectivity_plus_web=/opt/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_web-1.2.5/
|
||||
connectivity_plus_windows=/opt/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_windows-1.2.2/
|
||||
connectivity_plus=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.9/
|
||||
connectivity_plus_linux=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_linux-1.3.1/
|
||||
connectivity_plus_macos=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_macos-1.2.6/
|
||||
connectivity_plus_web=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_web-1.2.5/
|
||||
connectivity_plus_windows=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_windows-1.2.2/
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"connectivity_plus","path":"/opt/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.9/","native_build":true,"dependencies":[]}],"android":[{"name":"connectivity_plus","path":"/opt/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.9/","native_build":true,"dependencies":[]}],"macos":[{"name":"connectivity_plus_macos","path":"/opt/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_macos-1.2.6/","native_build":true,"dependencies":[]}],"linux":[{"name":"connectivity_plus_linux","path":"/opt/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_linux-1.3.1/","native_build":false,"dependencies":[]}],"windows":[{"name":"connectivity_plus_windows","path":"/opt/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_windows-1.2.2/","native_build":true,"dependencies":[]}],"web":[{"name":"connectivity_plus_web","path":"/opt/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_web-1.2.5/","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-10-12 22:11:05.557834","version":"3.3.4"}
|
||||
{"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.9/","native_build":true,"dependencies":[]}],"android":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.9/","native_build":true,"dependencies":[]}],"macos":[{"name":"connectivity_plus_macos","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_macos-1.2.6/","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.5/","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-12-14 11:46:01.321906","version":"3.3.8"}
|
||||
@@ -1,6 +1,6 @@
|
||||
# This is a generated file; do not edit or check into version control.
|
||||
connectivity_plus=/opt/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.9/
|
||||
connectivity_plus_linux=/opt/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_linux-1.3.1/
|
||||
connectivity_plus_macos=/opt/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_macos-1.2.4/
|
||||
connectivity_plus_web=/opt/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_web-1.2.5/
|
||||
connectivity_plus_windows=/opt/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_windows-1.2.2/
|
||||
connectivity_plus=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.9/
|
||||
connectivity_plus_linux=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_linux-1.3.1/
|
||||
connectivity_plus_macos=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_macos-1.2.4/
|
||||
connectivity_plus_web=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_web-1.2.5/
|
||||
connectivity_plus_windows=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_windows-1.2.2/
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"connectivity_plus","path":"/opt/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.9/","native_build":true,"dependencies":[]}],"android":[{"name":"connectivity_plus","path":"/opt/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.9/","native_build":true,"dependencies":[]}],"macos":[{"name":"connectivity_plus_macos","path":"/opt/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_macos-1.2.4/","native_build":true,"dependencies":[]}],"linux":[{"name":"connectivity_plus_linux","path":"/opt/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_linux-1.3.1/","native_build":false,"dependencies":[]}],"windows":[{"name":"connectivity_plus_windows","path":"/opt/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_windows-1.2.2/","native_build":true,"dependencies":[]}],"web":[{"name":"connectivity_plus_web","path":"/opt/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_web-1.2.5/","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-10-12 22:11:08.760671","version":"3.3.4"}
|
||||
{"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.9/","native_build":true,"dependencies":[]}],"android":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.9/","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.5/","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-12-14 11:46:05.508816","version":"3.3.8"}
|
||||
@@ -42,6 +42,9 @@ InfiniteQuery<T, Outside, PageParam>
|
||||
final oldOnError = usePrevious(onError);
|
||||
|
||||
final init = useCallback(([T? previousData]) {
|
||||
final hasExternalDataChanged = !isShallowEqual(
|
||||
infiniteQuery.value.externalData,
|
||||
infiniteQuery.value.prevUsedExternalData);
|
||||
infiniteQuery.value = queryBowl.addInfiniteQuery<T, Outside, PageParam>(
|
||||
job,
|
||||
externalData: externalData,
|
||||
@@ -50,10 +53,6 @@ InfiniteQuery<T, Outside, PageParam>
|
||||
onError: onError,
|
||||
);
|
||||
update();
|
||||
final hasExternalDataChanged = infiniteQuery.value.externalData != null &&
|
||||
infiniteQuery.value.prevUsedExternalData != null &&
|
||||
!isShallowEqual(infiniteQuery.value.externalData!,
|
||||
infiniteQuery.value.prevUsedExternalData!);
|
||||
if (infiniteQuery.value.fetched && hasExternalDataChanged) {
|
||||
infiniteQuery.value.refetchPages();
|
||||
} else if (!infiniteQuery.value.fetched) {
|
||||
@@ -95,42 +94,42 @@ InfiniteQuery<T, Outside, PageParam>
|
||||
}, []);
|
||||
|
||||
useEffect(() {
|
||||
final hasOnErrorChanged = oldOnError != onError && oldOnError != null;
|
||||
final hasOnDataChanged = oldOnData != onData && oldOnData != null;
|
||||
if (oldJob != null && oldJob.queryKey != job.queryKey) {
|
||||
disposeQuery();
|
||||
init();
|
||||
} else if (oldExternalData != null &&
|
||||
externalData != null &&
|
||||
!isShallowEqual(oldExternalData, externalData)) {
|
||||
if (job.refetchOnExternalDataChange ??
|
||||
queryBowl.refetchOnExternalDataChange) {
|
||||
QueryBowl.of(context).addInfiniteQuery(
|
||||
job,
|
||||
externalData: externalData,
|
||||
key: uKey,
|
||||
onData: onData,
|
||||
onError: onError,
|
||||
)..refetchPages();
|
||||
} else {
|
||||
QueryBowl.of(context)
|
||||
.getQuery(job.queryKey)
|
||||
?.setExternalData(externalData);
|
||||
}
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
final hasOnErrorChanged = oldOnError != onError && oldOnError != null;
|
||||
final hasOnDataChanged = oldOnData != onData && oldOnData != null;
|
||||
if (oldJob != null && oldJob.queryKey != job.queryKey) {
|
||||
disposeQuery();
|
||||
init();
|
||||
} else if (!isShallowEqual(oldExternalData, externalData)) {
|
||||
if (job.refetchOnExternalDataChange ??
|
||||
queryBowl.refetchOnExternalDataChange) {
|
||||
QueryBowl.of(context).addInfiniteQuery(
|
||||
job,
|
||||
externalData: externalData,
|
||||
key: uKey,
|
||||
onData: onData,
|
||||
onError: onError,
|
||||
)..refetchPages();
|
||||
} else {
|
||||
QueryBowl.of(context)
|
||||
.getQuery(job.queryKey)
|
||||
?.setExternalData(externalData);
|
||||
}
|
||||
|
||||
if (hasOnDataChanged) infiniteQuery.value.removeDataListener(oldOnData);
|
||||
if (hasOnErrorChanged)
|
||||
infiniteQuery.value.removeErrorListener(oldOnError);
|
||||
} else {
|
||||
if (hasOnDataChanged) {
|
||||
infiniteQuery.value.removeDataListener(oldOnData);
|
||||
if (onData != null) infiniteQuery.value.addDataListener(onData);
|
||||
if (hasOnDataChanged) infiniteQuery.value.removeDataListener(oldOnData);
|
||||
if (hasOnErrorChanged)
|
||||
infiniteQuery.value.removeErrorListener(oldOnError);
|
||||
} else {
|
||||
if (hasOnDataChanged) {
|
||||
infiniteQuery.value.removeDataListener(oldOnData);
|
||||
if (onData != null) infiniteQuery.value.addDataListener(onData);
|
||||
}
|
||||
if (hasOnErrorChanged) {
|
||||
infiniteQuery.value.removeErrorListener(oldOnError);
|
||||
if (onError != null) infiniteQuery.value.addErrorListener(onError);
|
||||
}
|
||||
}
|
||||
if (hasOnErrorChanged) {
|
||||
infiniteQuery.value.removeErrorListener(oldOnError);
|
||||
if (onError != null) infiniteQuery.value.addErrorListener(onError);
|
||||
}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
});
|
||||
|
||||
|
||||
@@ -75,23 +75,25 @@ Mutation<T, V> useMutation<T extends Object, V>({
|
||||
}, []);
|
||||
|
||||
useEffect(() {
|
||||
if (oldJob != null && oldJob.mutationKey != job.mutationKey) {
|
||||
disposeMutation();
|
||||
init();
|
||||
} else {
|
||||
if (oldOnData != onData && oldOnData != null) {
|
||||
mutation.value.removeDataListener(oldOnData);
|
||||
if (onData != null) mutation.value.addDataListener(onData);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (oldJob != null && oldJob.mutationKey != job.mutationKey) {
|
||||
disposeMutation();
|
||||
init();
|
||||
} else {
|
||||
if (oldOnData != onData && oldOnData != null) {
|
||||
mutation.value.removeDataListener(oldOnData);
|
||||
if (onData != null) mutation.value.addDataListener(onData);
|
||||
}
|
||||
if (oldOnError != onError && oldOnError != null) {
|
||||
mutation.value.removeErrorListener(oldOnError);
|
||||
if (onError != null) mutation.value.addErrorListener(onError);
|
||||
}
|
||||
if (oldOnMutate != onMutate && oldOnMutate != null) {
|
||||
mutation.value.removeMutateListener(oldOnMutate);
|
||||
if (onMutate != null) mutation.value.addMutateListener(onMutate);
|
||||
}
|
||||
}
|
||||
if (oldOnError != onError && oldOnError != null) {
|
||||
mutation.value.removeErrorListener(oldOnError);
|
||||
if (onError != null) mutation.value.addErrorListener(onError);
|
||||
}
|
||||
if (oldOnMutate != onMutate && oldOnMutate != null) {
|
||||
mutation.value.removeMutateListener(oldOnMutate);
|
||||
if (onMutate != null) mutation.value.addMutateListener(onMutate);
|
||||
}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
});
|
||||
|
||||
|
||||
@@ -41,6 +41,10 @@ Query<T, Outside> useQuery<T extends Object, Outside>({
|
||||
final oldOnError = usePrevious(onError);
|
||||
|
||||
final init = useCallback(([T? previousData]) {
|
||||
final hasExternalDataChanged = !isShallowEqual(
|
||||
query.value.externalData,
|
||||
query.value.prevUsedExternalData,
|
||||
);
|
||||
query.value = queryBowl.addQuery<T, Outside>(
|
||||
job,
|
||||
externalData: externalData,
|
||||
@@ -50,10 +54,6 @@ Query<T, Outside> useQuery<T extends Object, Outside>({
|
||||
onError: onError,
|
||||
);
|
||||
update();
|
||||
final hasExternalDataChanged = query.value.externalData != null &&
|
||||
query.value.prevUsedExternalData != null &&
|
||||
!isShallowEqual(
|
||||
query.value.externalData!, query.value.prevUsedExternalData!);
|
||||
if (query.value.fetched && hasExternalDataChanged) {
|
||||
query.value.refetch();
|
||||
} else if (!query.value.fetched) {
|
||||
@@ -82,51 +82,51 @@ Query<T, Outside> useQuery<T extends Object, Outside>({
|
||||
}, []);
|
||||
|
||||
useEffect(() {
|
||||
final hasOnErrorChanged = oldOnError != onError && oldOnError != null;
|
||||
final hasOnDataChanged = oldOnData != onData && oldOnData != null;
|
||||
if (oldJob != null && oldJob.queryKey != job.queryKey) {
|
||||
disposeQuery();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
final hasOnErrorChanged = oldOnError != onError && oldOnError != null;
|
||||
final hasOnDataChanged = oldOnData != onData && oldOnData != null;
|
||||
if (oldJob != null && oldJob.queryKey != job.queryKey) {
|
||||
disposeQuery();
|
||||
|
||||
/// setting the new query's initial data as prev query's data
|
||||
/// when [job.keepPreviousData] is true and both are dynamic
|
||||
if (oldJob.isDynamic &&
|
||||
job.isDynamic &&
|
||||
oldJob.keepPreviousData == true &&
|
||||
job.keepPreviousData == true) {
|
||||
init(query.value.data);
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
} else if (oldExternalData != null &&
|
||||
externalData != null &&
|
||||
!isShallowEqual(oldExternalData, externalData)) {
|
||||
if (job.refetchOnExternalDataChange ??
|
||||
queryBowl.refetchOnExternalDataChange) {
|
||||
QueryBowl.of(context).fetchQuery(
|
||||
job,
|
||||
externalData: externalData,
|
||||
onData: onData,
|
||||
onError: onError,
|
||||
key: uKey,
|
||||
);
|
||||
} else {
|
||||
QueryBowl.of(context)
|
||||
.getQuery(job.queryKey)
|
||||
?.setExternalData(externalData);
|
||||
}
|
||||
/// setting the new query's initial data as prev query's data
|
||||
/// when [job.keepPreviousData] is true and both are dynamic
|
||||
if (oldJob.isDynamic &&
|
||||
job.isDynamic &&
|
||||
oldJob.keepPreviousData == true &&
|
||||
job.keepPreviousData == true) {
|
||||
init(query.value.data);
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
} else if (!isShallowEqual(oldExternalData, externalData)) {
|
||||
if (job.refetchOnExternalDataChange ??
|
||||
queryBowl.refetchOnExternalDataChange) {
|
||||
QueryBowl.of(context).fetchQuery(
|
||||
job,
|
||||
externalData: externalData,
|
||||
onData: onData,
|
||||
onError: onError,
|
||||
key: uKey,
|
||||
);
|
||||
} else {
|
||||
QueryBowl.of(context)
|
||||
.getQuery(job.queryKey)
|
||||
?.setExternalData(externalData);
|
||||
}
|
||||
|
||||
if (hasOnDataChanged) query.value.removeDataListener(oldOnData);
|
||||
if (hasOnErrorChanged) query.value.removeErrorListener(oldOnError);
|
||||
} else {
|
||||
if (hasOnDataChanged) {
|
||||
query.value.removeDataListener(oldOnData);
|
||||
if (onData != null) query.value.addDataListener(onData);
|
||||
if (hasOnDataChanged) query.value.removeDataListener(oldOnData);
|
||||
if (hasOnErrorChanged) query.value.removeErrorListener(oldOnError);
|
||||
} else {
|
||||
if (hasOnDataChanged) {
|
||||
query.value.removeDataListener(oldOnData);
|
||||
if (onData != null) query.value.addDataListener(onData);
|
||||
}
|
||||
if (hasOnErrorChanged) {
|
||||
query.value.removeErrorListener(oldOnError);
|
||||
if (onError != null) query.value.addErrorListener(onError);
|
||||
}
|
||||
}
|
||||
if (hasOnErrorChanged) {
|
||||
query.value.removeErrorListener(oldOnError);
|
||||
if (onError != null) query.value.addErrorListener(onError);
|
||||
}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import 'package:fl_query/fl_query.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
|
||||
/// Simple hook based shorthand for [QueryBowl.of(context)]
|
||||
QueryBowl useQueryBowl() {
|
||||
final context = useContext();
|
||||
|
||||
return QueryBowl.of(context);
|
||||
}
|
||||
@@ -16,7 +16,8 @@ dependencies:
|
||||
sdk: flutter
|
||||
flutter_hooks: ^0.18.5+1
|
||||
uuid: ^3.0.6
|
||||
fl_query: ^0.3.1
|
||||
fl_query:
|
||||
path: ../fl_query
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user