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

View File

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