UNPKG

656 BPlain TextView Raw
1/* eslint-disable @typescript-eslint/no-unsafe-member-access */
2import type { AxiosCacheHooksOptions } from './options';
3import type { ApiCall } from './types';
4
5export function applyAbortController<D, A extends unknown[]>(
6 apiCall: ApiCall<D, A>,
7 options: AxiosCacheHooksOptions,
8 args: A,
9 abort: AbortController
10) {
11 const confIndex = options.configIndexFinder(apiCall, ...args);
12
13 args[confIndex] ??= {};
14
15 // Overriding the axios signal opens space
16 // to cancel the request if the component
17 // is unmounted before the request is resolved.
18 //@ts-expect-error - Trust the found parameter index.
19 args[confIndex].signal = abort.signal;
20}