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

Class MutationController

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

Source from the content-addressed store, hash-verified

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