Skip to content

Commit ac2afcf

Browse files
committed
fix(svelte-query): simplify creatMutation sub/unsub
1 parent f919a0f commit ac2afcf

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

packages/svelte-query/src/createMutation.svelte.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { onDestroy } from 'svelte'
2-
31
import { MutationObserver, noop, notifyManager } from '@tanstack/query-core'
42
import { useQueryClient } from './useQueryClient.js'
53
import { watchChanges } from './utils.svelte.js'
@@ -57,22 +55,13 @@ export function createMutation<
5755

5856
let result = $derived(observer.getCurrentResult())
5957

60-
const subscribe = (
61-
observer: MutationObserver<TData, TError, TVariables, TContext>,
62-
) =>
63-
observer.subscribe((val) => {
58+
$effect.pre(() => {
59+
const unsubscribe = observer.subscribe((val) => {
6460
notifyManager.batchCalls(() => {
6561
Object.assign(result, val)
6662
})()
6763
})
68-
let unsubscribe = $state(subscribe(observer))
69-
70-
$effect.pre(() => {
71-
unsubscribe = subscribe(observer)
72-
})
73-
74-
onDestroy(() => {
75-
unsubscribe()
64+
return unsubscribe
7665
})
7766

7867
const resultProxy = $derived(

0 commit comments

Comments
 (0)