mirror of
https://github.com/arthurfiorette/axios-cache-interceptor.git
synced 2025-12-08 17:36:16 +00:00
refactor: use the same object for both properties
This commit is contained in:
parent
b861277b9f
commit
47349df09f
@ -61,13 +61,17 @@ export function applyCache(
|
|||||||
/**
|
/**
|
||||||
* Returns a new axios instance with caching enabled.
|
* Returns a new axios instance with caching enabled.
|
||||||
*
|
*
|
||||||
* @param config The config for the caching interceptors
|
* @param config The config for the caching interceptors and the axios instance
|
||||||
* @param axiosConfig The config for the created axios instance
|
* @returns A new AxiosCacheInstance with caching enabled
|
||||||
* @returns The same instance but with caching enabled
|
|
||||||
*/
|
*/
|
||||||
export function createCache(
|
export function createCache({
|
||||||
config: Partial<CacheInstance> & Partial<CacheProperties> = {},
|
axios = {},
|
||||||
axiosConfig: AxiosRequestConfig = {}
|
cache = {}
|
||||||
): AxiosCacheInstance {
|
}: CreateCacheOptions = {}): AxiosCacheInstance {
|
||||||
return applyCache(Axios.create(axiosConfig), config);
|
return applyCache(Axios.create(axios), cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type CreateCacheOptions = {
|
||||||
|
axios?: Partial<AxiosRequestConfig>;
|
||||||
|
cache?: Partial<CacheInstance> & Partial<CacheProperties>;
|
||||||
|
};
|
||||||
|
|||||||
@ -11,8 +11,7 @@ export function mockAxios(
|
|||||||
headers: Record<string, string> = {}
|
headers: Record<string, string> = {}
|
||||||
): AxiosCacheInstance {
|
): AxiosCacheInstance {
|
||||||
const axios = createCache({
|
const axios = createCache({
|
||||||
// Defaults to cache every request
|
cache: options
|
||||||
...options
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Axios interceptors are a stack, so apply this after the cache interceptor
|
// Axios interceptors are a stack, so apply this after the cache interceptor
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user