MCPcopy Create free account
hub / github.com/TanStack/query / MutationController

Class MutationController

packages/lit-query/src/createMutationController.ts:100–284  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98}
99
100class MutationController<
101 TData,
102 TError,
103 TVariables,
104 TOnMutateResult,
105> extends BaseController<
106 MutationObserverResult<TData, TError, TVariables, TOnMutateResult>
107> {
108 private readonly options: Accessor<
109 CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>
110 >
111 private observer:
112 | MutationObserver<TData, TError, TVariables, TOnMutateResult>
113 | undefined
114 private unsubscribe: (() => void) | undefined
115 private queryClient: QueryClient | undefined
116
117 constructor(
118 host: ReactiveControllerHost,
119 options: Accessor<
120 CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>
121 >,
122 queryClient?: QueryClient,
123 ) {
124 super(host, createIdleMutationResult(), queryClient)
125 this.options = options
126
127 if (!queryClient) {
128 return
129 }
130
131 if (typeof options === 'function') {
132 return
133 }
134
135 const observer = new MutationObserver(
136 queryClient,
137 this.defaultOptions(queryClient),
138 )
139 this.queryClient = queryClient
140 this.observer = observer
141 this.result = observer.getCurrentResult()
142 }
143
144 protected override onConnected(): void {
145 if (!this.syncClient()) {
146 return
147 }
148
149 this.refreshOptions()
150 this.subscribe()
151 if (this.observer) {
152 this.setResult(this.observer.getCurrentResult())
153 }
154 }
155
156 protected override onDisconnected(): void {
157 this.unsubscribeObserver()

Callers

nothing calls this directly

Calls 5

syncClientMethod · 0.95
mutateMethod · 0.45
resetMethod · 0.45
getCurrentResultMethod · 0.45

Tested by

no test coverage detected