(
options:
| MutationStateOptions<TResult>
| (() => MutationStateOptions<TResult>) = {},
queryClient?: QueryClient,
)
| 66 | } |
| 67 | |
| 68 | export function useMutationState<TResult = MutationState>( |
| 69 | options: |
| 70 | | MutationStateOptions<TResult> |
| 71 | | (() => MutationStateOptions<TResult>) = {}, |
| 72 | queryClient?: QueryClient, |
| 73 | ): Readonly<Ref<Array<TResult>>> { |
| 74 | const resolvedOptions = computed(() => { |
| 75 | const newOptions = typeof options === 'function' ? options() : options |
| 76 | return { |
| 77 | filters: cloneDeepUnref(newOptions.filters), |
| 78 | select: newOptions.select, |
| 79 | } |
| 80 | }) |
| 81 | const mutationCache = (queryClient || useQueryClient()).getMutationCache() |
| 82 | const state = shallowRef(getResult(mutationCache, resolvedOptions.value)) |
| 83 | const unsubscribe = mutationCache.subscribe(() => { |
| 84 | state.value = getResult(mutationCache, resolvedOptions.value) |
| 85 | }) |
| 86 | |
| 87 | watch(resolvedOptions, () => { |
| 88 | state.value = getResult(mutationCache, resolvedOptions.value) |
| 89 | }) |
| 90 | |
| 91 | onScopeDispose(() => { |
| 92 | unsubscribe() |
| 93 | }) |
| 94 | |
| 95 | return shallowReadonly(state) |
| 96 | } |
no test coverage detected