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

Method remove

packages/query-core/src/mutationCache.ts:186–207  ·  view source on GitHub ↗

* Removes a mutation from the cache. * @internal * @param mutation - The mutation to remove, also from its scope's queue.

(mutation: Mutation<any, any, any, any>)

Source from the content-addressed store, hash-verified

184 * @param mutation - The mutation to remove, also from its scope's queue.
185 */
186 remove(mutation: Mutation<any, any, any, any>): void {
187 if (this.#mutations.delete(mutation)) {
188 const scope = scopeFor(mutation)
189 if (typeof scope === 'string') {
190 const scopedMutations = this.#scopes.get(scope)
191 if (scopedMutations) {
192 if (scopedMutations.length > 1) {
193 const index = scopedMutations.indexOf(mutation)
194 if (index !== -1) {
195 scopedMutations.splice(index, 1)
196 }
197 } else if (scopedMutations[0] === mutation) {
198 this.#scopes.delete(scope)
199 }
200 }
201 }
202 }
203
204 // Currently we notify the removal even if the mutation was already removed.
205 // Consider making this an error or not notifying of the removal depending on the desired semantics.
206 this.notify({ type: 'removed', mutation })
207 }
208
209 /**
210 * Checks whether a mutation can run now, given the other mutations in its `scope`.

Callers

nothing calls this directly

Calls 3

notifyMethod · 0.95
scopeForFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected