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.
|
||||
*
|
||||
* @param config The config for the caching interceptors
|
||||
* @param axiosConfig The config for the created axios instance
|
||||
* @returns The same instance but with caching enabled
|
||||
* @param config The config for the caching interceptors and the axios instance
|
||||
* @returns A new AxiosCacheInstance with caching enabled
|
||||
*/
|
||||
export function createCache(
|
||||
config: Partial<CacheInstance> & Partial<CacheProperties> = {},
|
||||
axiosConfig: AxiosRequestConfig = {}
|
||||
): AxiosCacheInstance {
|
||||
return applyCache(Axios.create(axiosConfig), config);
|
||||
export function createCache({
|
||||
axios = {},
|
||||
cache = {}
|
||||
}: CreateCacheOptions = {}): AxiosCacheInstance {
|
||||
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> = {}
|
||||
): AxiosCacheInstance {
|
||||
const axios = createCache({
|
||||
// Defaults to cache every request
|
||||
...options
|
||||
cache: options
|
||||
});
|
||||
|
||||
// Axios interceptors are a stack, so apply this after the cache interceptor
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user