Skip to content

Commit

Permalink
fix(useMutationState): fix test
Browse files Browse the repository at this point in the history
useMutationState should properly update filters
  • Loading branch information
juvirez committed May 23, 2023
1 parent 25d27d8 commit 9ba3075
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/vue-query/src/useMutationState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { onScopeDispose, readonly, computed, ref } from 'vue-demi'
import { onScopeDispose, readonly, computed, ref, watch } from 'vue-demi'
import type { Ref, DeepReadonly } from 'vue-demi'
import type {
MutationFilters as MF,
Expand Down Expand Up @@ -57,13 +57,22 @@ export function useMutationState<TResult = MutationState>(
options: MutationStateOptions<TResult> = {},
queryClient?: QueryClient,
): DeepReadonly<Ref<Array<TResult>>> {
const filters = computed(() => cloneDeepUnref(options.filters))
const mutationCache = (queryClient || useQueryClient()).getMutationCache()
const state = ref(getResult(mutationCache, options)) as Ref<TResult[]>
const unsubscribe = mutationCache.subscribe(() => {
const result = getResult(mutationCache, options)
state.value = result
})

watch(
filters,
() => {
state.value = getResult(mutationCache, options)
},
{ deep: true },
)

onScopeDispose(() => {
unsubscribe()
})
Expand Down

0 comments on commit 9ba3075

Please sign in to comment.