Skip to main content
Version: v8.0.0

RequestManager

Request Manager is used to emit request lifecycle events like - request start, request end, upload and download progress. It is also the place of request aborting system, here we store all the keys and controllers that are isolated for each client instance.


Import
import { RequestManager } from "@hyper-fetch/core"

Parameters​

class RequestManager {
constructor() {};
events: { emitAbort: (data: RequestEventType<RequestInstance>, isTriggeredExternally: boolean) => void; emitDeduplicated: (data: RequestDeduplicatedEventType<RequestInstance>, isTriggeredExternally: boolean) => void; emitDownloadProgress: (data: RequestProgressEventType<RequestInstance>, isTriggeredExternally: boolean) => void; emitLoading: (data: RequestLoadingEventType<RequestInstance>, isTriggeredExternally: boolean) => void; emitRemove: (data: RequestRemovedEventType<RequestInstance>, isTriggeredExternally: boolean) => void; emitRequestStart: (data: RequestEventType<RequestInstance>, isTriggeredExternally: boolean) => void; emitResponse: <Adapter>(data: RequestResponseEventType<ExtendRequest<RequestInstance, { client: Client<any, Adapter> }>>, isTriggeredExternally: boolean) => void; emitResponseStart: (data: RequestEventType<RequestInstance>, isTriggeredExternally: boolean) => void; emitUploadProgress: (data: RequestProgressEventType<RequestInstance>, isTriggeredExternally: boolean) => void; onAbort: <T>(callback: (request: RequestEventType<T>) => void) => VoidFunction; onAbortById: <T>(requestId: string, callback: (data: RequestEventType<T>) => void) => VoidFunction; onAbortByKey: <T>(abortKey: string, callback: (request: RequestEventType<T>) => void) => VoidFunction; onDeduplicated: <T>(callback: (data: RequestDeduplicatedEventType<T>) => void) => VoidFunction; onDeduplicatedByCache: <T>(cacheKey: string, callback: (data: RequestDeduplicatedEventType<T>) => void) => VoidFunction; onDeduplicatedById: <T>(requestId: string, callback: (data: RequestDeduplicatedEventType<T>) => void) => VoidFunction; onDeduplicatedByQueue: <T>(queryKey: string, callback: (data: RequestDeduplicatedEventType<T>) => void) => VoidFunction; onDownloadProgress: <T>(callback: (data: RequestProgressEventType<T>) => void) => VoidFunction; onDownloadProgressById: <T>(requestId: string, callback: (data: RequestProgressEventType<T>) => void) => VoidFunction; onDownloadProgressByQueue: <T>(queryKey: string, callback: (data: RequestProgressEventType<T>) => void) => VoidFunction; onLoading: <T>(callback: (data: RequestLoadingEventType<T>) => void) => VoidFunction; onLoadingByCache: <T>(cacheKey: string, callback: (data: RequestLoadingEventType<T>) => void) => VoidFunction; onLoadingById: <T>(requestId: string, callback: (data: RequestLoadingEventType<T>) => void) => VoidFunction; onLoadingByQueue: <T>(queryKey: string, callback: (data: RequestLoadingEventType<T>) => void) => VoidFunction; onRemove: <T>(callback: (data: RequestRemovedEventType<T>) => void) => VoidFunction; onRemoveById: <T>(requestId: string, callback: (data: RequestRemovedEventType<T>) => void) => VoidFunction; onRemoveByQueue: <T>(queryKey: string, callback: (data: RequestRemovedEventType<T>) => void) => VoidFunction; onRequestStart: <T>(callback: (details: RequestEventType<T>) => void) => VoidFunction; onRequestStartById: <T>(requestId: string, callback: (details: RequestEventType<T>) => void) => VoidFunction; onRequestStartByQueue: <T>(queryKey: string, callback: (details: RequestEventType<T>) => void) => VoidFunction; onResponse: <T>(callback: (data: RequestResponseEventType<T>) => void) => VoidFunction; onResponseByCache: <T>(cacheKey: string, callback: (data: RequestResponseEventType<T>) => void) => VoidFunction; onResponseById: <T>(requestId: string, callback: (data: RequestResponseEventType<T>) => void) => VoidFunction; onResponseStart: <T>(callback: (details: RequestEventType<T>) => void) => VoidFunction; onResponseStartById: <T>(requestId: string, callback: (details: RequestEventType<T>) => void) => VoidFunction; onResponseStartByQueue: <T>(queryKey: string, callback: (details: RequestEventType<T>) => void) => VoidFunction; onUploadProgress: <T>(callback: (data: RequestProgressEventType<T>) => void) => VoidFunction; onUploadProgressById: <T>(requestId: string, callback: (data: RequestProgressEventType<T>) => void) => VoidFunction; onUploadProgressByQueue: <T>(queryKey: string, callback: (data: RequestProgressEventType<T>) => void) => VoidFunction };
emitter: EventEmitter;
abortControllers: Map<string, Map<string, AbortController>>;
abortAll() => void;
abortByKey(abortKey: string) => void;
abortByRequestId(abortKey: string, requestId: string) => void;
addAbortController(abortKey: string, requestId: string) => void;
getAbortController(abortKey: string, requestId: string) => undefined | AbortController;
removeAbortController(abortKey: string, requestId: string) => void;
useAbortController(abortKey: string, requestId: string) => void;
}

Properties​

abortControllers​

Type
Map<string, Map<string, AbortController>>

emitter​

Type
EventEmitter

events​

Type
{ emitAbort: (data: RequestEventType<RequestInstance>, isTriggeredExternally: boolean) => void; emitDeduplicated: (data: RequestDeduplicatedEventType<RequestInstance>, isTriggeredExternally: boolean) => void; emitDownloadProgress: (data: RequestProgressEventType<RequestInstance>, isTriggeredExternally: boolean) => void; emitLoading: (data: RequestLoadingEventType<RequestInstance>, isTriggeredExternally: boolean) => void; emitRemove: (data: RequestRemovedEventType<RequestInstance>, isTriggeredExternally: boolean) => void; emitRequestStart: (data: RequestEventType<RequestInstance>, isTriggeredExternally: boolean) => void; emitResponse: <Adapter>(data: RequestResponseEventType<ExtendRequest<RequestInstance, { client: Client<any, Adapter> }>>, isTriggeredExternally: boolean) => void; emitResponseStart: (data: RequestEventType<RequestInstance>, isTriggeredExternally: boolean) => void; emitUploadProgress: (data: RequestProgressEventType<RequestInstance>, isTriggeredExternally: boolean) => void; onAbort: <T>(callback: (request: RequestEventType<T>) => void) => VoidFunction; onAbortById: <T>(requestId: string, callback: (data: RequestEventType<T>) => void) => VoidFunction; onAbortByKey: <T>(abortKey: string, callback: (request: RequestEventType<T>) => void) => VoidFunction; onDeduplicated: <T>(callback: (data: RequestDeduplicatedEventType<T>) => void) => VoidFunction; onDeduplicatedByCache: <T>(cacheKey: string, callback: (data: RequestDeduplicatedEventType<T>) => void) => VoidFunction; onDeduplicatedById: <T>(requestId: string, callback: (data: RequestDeduplicatedEventType<T>) => void) => VoidFunction; onDeduplicatedByQueue: <T>(queryKey: string, callback: (data: RequestDeduplicatedEventType<T>) => void) => VoidFunction; onDownloadProgress: <T>(callback: (data: RequestProgressEventType<T>) => void) => VoidFunction; onDownloadProgressById: <T>(requestId: string, callback: (data: RequestProgressEventType<T>) => void) => VoidFunction; onDownloadProgressByQueue: <T>(queryKey: string, callback: (data: RequestProgressEventType<T>) => void) => VoidFunction; onLoading: <T>(callback: (data: RequestLoadingEventType<T>) => void) => VoidFunction; onLoadingByCache: <T>(cacheKey: string, callback: (data: RequestLoadingEventType<T>) => void) => VoidFunction; onLoadingById: <T>(requestId: string, callback: (data: RequestLoadingEventType<T>) => void) => VoidFunction; onLoadingByQueue: <T>(queryKey: string, callback: (data: RequestLoadingEventType<T>) => void) => VoidFunction; onRemove: <T>(callback: (data: RequestRemovedEventType<T>) => void) => VoidFunction; onRemoveById: <T>(requestId: string, callback: (data: RequestRemovedEventType<T>) => void) => VoidFunction; onRemoveByQueue: <T>(queryKey: string, callback: (data: RequestRemovedEventType<T>) => void) => VoidFunction; onRequestStart: <T>(callback: (details: RequestEventType<T>) => void) => VoidFunction; onRequestStartById: <T>(requestId: string, callback: (details: RequestEventType<T>) => void) => VoidFunction; onRequestStartByQueue: <T>(queryKey: string, callback: (details: RequestEventType<T>) => void) => VoidFunction; onResponse: <T>(callback: (data: RequestResponseEventType<T>) => void) => VoidFunction; onResponseByCache: <T>(cacheKey: string, callback: (data: RequestResponseEventType<T>) => void) => VoidFunction; onResponseById: <T>(requestId: string, callback: (data: RequestResponseEventType<T>) => void) => VoidFunction; onResponseStart: <T>(callback: (details: RequestEventType<T>) => void) => VoidFunction; onResponseStartById: <T>(requestId: string, callback: (details: RequestEventType<T>) => void) => VoidFunction; onResponseStartByQueue: <T>(queryKey: string, callback: (details: RequestEventType<T>) => void) => VoidFunction; onUploadProgress: <T>(callback: (data: RequestProgressEventType<T>) => void) => VoidFunction; onUploadProgressById: <T>(requestId: string, callback: (data: RequestProgressEventType<T>) => void) => VoidFunction; onUploadProgressByQueue: <T>(queryKey: string, callback: (data: RequestProgressEventType<T>) => void) => VoidFunction }

Methods​

abortAll()​

Preview
abortAll()
Returns
void

abortByKey()​

Preview
abortByKey(abortKey: string)
Parameters
Parameters
NameTypeDescription
abortKey
string
Returns
void

abortByRequestId()​

Preview
abortByRequestId(abortKey: string, requestId: string)
Parameters
Parameters
NameTypeDescription
abortKey
string
requestId
string
Returns
void

addAbortController()​

Preview
addAbortController(abortKey: string, requestId: string)
Parameters
Parameters
NameTypeDescription
abortKey
string
requestId
string
Returns
void

getAbortController()​

Preview
getAbortController(abortKey: string, requestId: string)
Parameters
Parameters
NameTypeDescription
abortKey
string
requestId
string
Returns
undefined | AbortController

removeAbortController()​

Preview
removeAbortController(abortKey: string, requestId: string)
Parameters
Parameters
NameTypeDescription
abortKey
string
requestId
string
Returns
void

useAbortController()​

Preview
useAbortController(abortKey: string, requestId: string)
Parameters
Parameters
NameTypeDescription
abortKey
string
requestId
string
Returns
void