@tanstack/vue-query 4.13.0 → 4.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3121,6 +3121,9 @@
3121
3121
  function isQueryKey(value) {
3122
3122
  return Array.isArray(value);
3123
3123
  }
3124
+ function isMutationKey(value) {
3125
+ return Array.isArray(value);
3126
+ }
3124
3127
  function updateState(state, update) {
3125
3128
  Object.keys(state).forEach(key => {
3126
3129
  state[key] = update[key];
@@ -4727,12 +4730,13 @@
4727
4730
  }
4728
4731
 
4729
4732
  function useMutation(arg1, arg2, arg3) {
4730
- var _options$queryClient;
4733
+ var _options$value$queryC;
4731
4734
 
4732
- const options = parseMutationArgs(arg1, arg2, arg3);
4733
- const queryClient = (_options$queryClient = options.queryClient) != null ? _options$queryClient : useQueryClient(options.queryClientKey);
4734
- const defaultedOptions = queryClient.defaultMutationOptions(options);
4735
- const observer = new MutationObserver(queryClient, defaultedOptions);
4735
+ const options = vueDemi.computed(() => {
4736
+ return parseMutationArgs(arg1, arg2, arg3);
4737
+ });
4738
+ const queryClient = (_options$value$queryC = options.value.queryClient) != null ? _options$value$queryC : useQueryClient(options.value.queryClientKey);
4739
+ const observer = new MutationObserver(queryClient, queryClient.defaultMutationOptions(options.value));
4736
4740
  const state = vueDemi.reactive(observer.getCurrentResult());
4737
4741
  const unsubscribe = observer.subscribe(result => {
4738
4742
  updateState(state, result);
@@ -4743,8 +4747,8 @@
4743
4747
  });
4744
4748
  };
4745
4749
 
4746
- vueDemi.watch([() => arg1, () => arg2, () => arg3], () => {
4747
- observer.setOptions(queryClient.defaultMutationOptions(parseMutationArgs(arg1, arg2, arg3)));
4750
+ vueDemi.watch(options, () => {
4751
+ observer.setOptions(queryClient.defaultMutationOptions(options.value));
4748
4752
  }, {
4749
4753
  deep: true
4750
4754
  });
@@ -4759,24 +4763,27 @@
4759
4763
  };
4760
4764
  }
4761
4765
  function parseMutationArgs(arg1, arg2, arg3) {
4762
- let options = arg1;
4763
-
4764
- if (isQueryKey(arg1)) {
4765
- if (typeof arg2 === 'function') {
4766
- options = { ...arg3,
4767
- mutationKey: arg1,
4768
- mutationFn: arg2
4766
+ const plainArg1 = vueDemi.isRef(arg1) ? arg1.value : arg1;
4767
+ const plainArg2 = vueDemi.isRef(arg2) ? arg2.value : arg2;
4768
+ let options = plainArg1;
4769
+
4770
+ if (isMutationKey(plainArg1)) {
4771
+ if (typeof plainArg2 === 'function') {
4772
+ const plainArg3 = vueDemi.isRef(arg3) ? arg3.value : arg3;
4773
+ options = { ...plainArg3,
4774
+ mutationKey: plainArg1,
4775
+ mutationFn: plainArg2
4769
4776
  };
4770
4777
  } else {
4771
- options = { ...arg2,
4772
- mutationKey: arg1
4778
+ options = { ...plainArg2,
4779
+ mutationKey: plainArg1
4773
4780
  };
4774
4781
  }
4775
4782
  }
4776
4783
 
4777
- if (typeof arg1 === 'function') {
4778
- options = { ...arg2,
4779
- mutationFn: arg1
4784
+ if (typeof plainArg1 === 'function') {
4785
+ options = { ...plainArg2,
4786
+ mutationFn: plainArg1
4780
4787
  };
4781
4788
  }
4782
4789