@tanstack/vue-query 4.13.0 → 4.13.1

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(vueDemi.isRef(value) ? value.value : 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
  });
@@ -4761,11 +4765,14 @@
4761
4765
  function parseMutationArgs(arg1, arg2, arg3) {
4762
4766
  let options = arg1;
4763
4767
 
4764
- if (isQueryKey(arg1)) {
4765
- if (typeof arg2 === 'function') {
4766
- options = { ...arg3,
4768
+ if (isMutationKey(arg1)) {
4769
+ const plainFn = vueDemi.isRef(arg2) ? arg2.value : arg2;
4770
+ const plainOptions = vueDemi.isRef(arg3) ? arg3.value : arg3;
4771
+
4772
+ if (typeof plainFn === 'function') {
4773
+ options = { ...plainOptions,
4767
4774
  mutationKey: arg1,
4768
- mutationFn: arg2
4775
+ mutationFn: plainFn
4769
4776
  };
4770
4777
  } else {
4771
4778
  options = { ...arg2,
@@ -4774,9 +4781,12 @@
4774
4781
  }
4775
4782
  }
4776
4783
 
4777
- if (typeof arg1 === 'function') {
4778
- options = { ...arg2,
4779
- mutationFn: arg1
4784
+ const plainFn = vueDemi.isRef(arg1) ? arg1.value : arg1;
4785
+ const plainOptions = vueDemi.isRef(arg2) ? arg2.value : arg2;
4786
+
4787
+ if (typeof plainFn === 'function') {
4788
+ options = { ...plainOptions,
4789
+ mutationFn: plainFn
4780
4790
  };
4781
4791
  }
4782
4792