6 KiB
| id | title |
|---|---|
| MutationCache | MutationCache |
Defined in: packages/vue-query/src/mutationCache.ts:15
Vue-aware subclass of @tanstack/query-core's MutationCache. find/findAll also accept a
MaybeRefDeep filters object, so refs can be passed directly without unwrapping. Access it via
queryClient.getMutationCache() — QueryClient constructs one of these by default.
Extends
MutationCache
Constructors
Constructor
new MutationCache(config: MutationCacheConfig): MutationCache;
Defined in: packages/query-core/src/mutationCache.ts:128
Parameters
config
MutationCacheConfig = {}
Returns
MutationCache
Inherited from
MC.constructor
Properties
config
config: MutationCacheConfig = {};
Defined in: packages/query-core/src/mutationCache.ts:128
Inherited from
MC.config
Methods
clear()
clear(): void;
Defined in: packages/query-core/src/mutationCache.ts:257
Removes all mutations from the cache.
Returns
void
Example
const mutationCache = queryClient.getMutationCache()
mutationCache.clear()
Inherited from
MC.clear
find()
find<TData, TError, TVariables, TOnMutateResult>(filters: MaybeRefDeep<MutationFilters<unknown, Error, unknown, unknown>>):
| Mutation<TData, TError, TVariables, TOnMutateResult>
| undefined;
Defined in: packages/vue-query/src/mutationCache.ts:16
A slightly more advanced method that can be used to get an existing mutation instance from
the cache. If the mutation does not exist, undefined is returned.
This is not typically needed for most applications, but can come in handy when needing more information about a mutation in rare scenarios.
Type Parameters
TData
TData = unknown
TError
TError = Error
TVariables
TVariables = any
TOnMutateResult
TOnMutateResult = unknown
Parameters
filters
MaybeRefDeep<MutationFilters<unknown, Error, unknown, unknown>>
The filters to match. exact defaults to true.
Returns
| Mutation<TData, TError, TVariables, TOnMutateResult>
| undefined
The first matching mutation, or undefined.
See
Example
const mutationCache = queryClient.getMutationCache()
const mutation = mutationCache.find({ mutationKey: ['addPost'] })
Overrides
MC.find
findAll()
findAll(filters: MaybeRefDeep<MutationFilters<unknown, Error, unknown, unknown>>): Mutation<unknown, Error, unknown, unknown>[];
Defined in: packages/vue-query/src/mutationCache.ts:27
An even more advanced method that can be used to get existing mutation instances from the cache that match the given filters. If no mutations match, an empty array is returned.
This is not typically needed for most applications, but can come in handy when needing more information about mutations in rare scenarios.
Parameters
filters
MaybeRefDeep<MutationFilters<unknown, Error, unknown, unknown>> = {}
The filters to match. Without filters, every mutation is returned.
Returns
Mutation<unknown, Error, unknown, unknown>[]
The matching mutations.
See
Example
const mutationCache = queryClient.getMutationCache()
const mutations = mutationCache.findAll({ mutationKey: ['addPost'] })
Overrides
MC.findAll
getAll()
getAll(): Mutation<unknown, Error, unknown, unknown>[];
Defined in: packages/query-core/src/mutationCache.ts:280
Returns all mutations within the cache.
This is not typically needed for most applications, but can come in handy when needing more information about a mutation in rare scenarios.
Returns
Mutation<unknown, Error, unknown, unknown>[]
Every mutation in the cache.
Example
const mutationCache = queryClient.getMutationCache()
const mutations = mutationCache.getAll()
Inherited from
MC.getAll
hasListeners()
hasListeners(): boolean;
Defined in: packages/query-core/src/subscribable.ts:41
Returns true while at least one listener is registered, false once they have all unsubscribed.
Returns
boolean
Inherited from
MC.hasListeners
subscribe()
subscribe(listener: MutationCacheListener): () => void;
Defined in: packages/query-core/src/subscribable.ts:27
Registers a listener to be called on every update this object notifies about. Returns a function
that removes the listener again — call it to stop listening. The base class never drops a listener
on its own, though some subclasses clear all of theirs in destroy().
Parameters
listener
MutationCacheListener
Called on each update, with whatever the subclass passes to its subscribers.
Returns
(): void;
Returns
void
Example
const unsubscribe = subscribable.subscribe(() => {
// react to the update
})
unsubscribe()
Inherited from
MC.subscribe