refactor: use the same object for both properties

This commit is contained in:
Hazork 2021-09-26 15:44:35 -03:00
parent b861277b9f
commit 47349df09f
2 changed files with 13 additions and 10 deletions

View File

@ -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>;
};

View File

@ -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