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

Class MutationController

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

Source from the content-addressed store, hash-verified

109}
110
111class MutationController<
112 TData,
113 TError,
114 TVariables,
115 TOnMutateResult,
116> extends BaseController<
117 MutationObserverResult<TData, TError, TVariables, TOnMutateResult>
118> {
119 private readonly options: Accessor<
120 CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>
121 >
122 private observer:
123 | MutationObserver<TData, TError, TVariables, TOnMutateResult>
124 | undefined
125 private unsubscribe: (() => void) | undefined
126 private queryClient: QueryClient | undefined
127
128 constructor(
129 host: ReactiveControllerHost,
130 options: Accessor<
131 CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>
132 >,
133 queryClient?: QueryClient,
134 ) {
135 super(host, createIdleMutationResult(), queryClient)
136 this.options = options
137
138 if (!queryClient) {
139 return
140 }
141
142 if (typeof options === 'function') {
143 return
144 }
145
146 const observer = new MutationObserver(
147 queryClient,
148 this.defaultOptions(queryClient),
149 )
150 this.queryClient = queryClient
151 this.observer = observer
152 this.result = observer.getCurrentResult()
153 }
154
155 protected onConnected(): void {
156 if (!this.syncClient()) {
157 return
158 }
159
160 this.refreshOptions()
161 this.subscribe()
162 if (this.observer) {
163 this.setResult(this.observer.getCurrentResult())
164 }
165 }
166
167 protected onDisconnected(): void {
168 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