Skip to main content

Managers

The library contains several managers, they are mainly used to support smaller subsystems and features.


AppManager


This class is responsible for the state of our application in terms of online or offline status and whether the application window is focused or blurred.

For example, if we want to use hyper-fetch in a react native environment, our default web browser events won't work, we need to set the ones that are most optimal for the current environment.

info

Events listeners in the Hyper Fetch returns the unmounting callback for easier cleanup handling.

const unmountFocusListener = builder.commandManager.events.onFocus(console.log);
const unmountOfflineListener = builder.commandManager.events.onOffline(console.log);

...

unmountFocusListener()
unmountOfflineListener()

Events

Name Type Description
emitBlur () => void -
emitFocus () => void -
emitOffline () => void -
emitOnline () => void -
onBlur (callback: () => void) => VoidFunction -
onFocus (callback: () => void) => VoidFunction -
onOffline (callback: () => void) => VoidFunction -
onOnline (callback: () => void) => VoidFunction -


CommandManager


The CommandManager is responsible for holding the cancellation tokens needed to terminate the requests and for the events related to the requests lifecycle - request start, upload, download, response and abort.

info

Events listeners in the Hyper Fetch returns the unmounting callback for easier cleanup handling.


const unmountUploadListener = builder.commandManager.events.onUploadProgressById(requestId, console.log);
const unmountDownloadListener = builder.commandManager.events.onDownloadProgressById(requestId, console.log);

...

unmountUploadListener()
unmountDownloadListener()

AbortKey

Every requests which gets added to the dispatcher creates the abort controller for itself that's placed in Map object and it's stored there under abort key and requestId in it. This way we can abort whole groups of requests by abortKey or single requests by their requestId. By default it is automatically created on command out of it's endpoint and method, but we an set the custom value for easier usage.

Events

Name Type Description
emitAbort (abortKey: string, requestId: string, command: CommandInstance) => void -
emitDownloadProgress (queueKey: string, requestId: string, values: FetchProgressType, details: CommandEventDetails<CommandInstance>) => void -
emitLoading (queueKey: string, requestId: string, values: CommandLoadingEventType) => void -
emitRemove (queueKey: string, requestId: string, details: CommandEventDetails<T>) => void -
emitRequestStart (queueKey: string, requestId: string, details: CommandEventDetails<CommandInstance>) => void -
emitResponse (cacheKey: string, requestId: string, response: ClientResponseType<unknown, unknown>, details: CommandResponseDetails) => void -
emitResponseStart (queueKey: string, requestId: string, details: CommandEventDetails<CommandInstance>) => void -
emitUploadProgress (queueKey: string, requestId: string, values: FetchProgressType, details: CommandEventDetails<CommandInstance>) => void -
onAbort (abortKey: string, callback: (command: CommandInstance) => void) => VoidFunction -
onAbortById (requestId: string, callback: (command: CommandInstance) => void) => VoidFunction -
onDownloadProgress (queueKey: string, callback: (values: FetchProgressType, details: CommandEventDetails<T>) => void) => VoidFunction -
onDownloadProgressById (requestId: string, callback: (values: FetchProgressType, details: CommandEventDetails<T>) => void) => VoidFunction -
onLoading (queueKey: string, callback: (values: CommandLoadingEventType) => void) => VoidFunction -
onLoadingById (requestId: string, callback: (values: CommandLoadingEventType) => void) => VoidFunction -
onRemove (queueKey: string, callback: (details: CommandEventDetails<T>) => void) => VoidFunction -
onRemoveById (requestId: string, callback: (details: CommandEventDetails<T>) => void) => VoidFunction -
onRequestStart (queueKey: string, callback: (details: CommandEventDetails<T>) => void) => VoidFunction -
onRequestStartById (requestId: string, callback: (details: CommandEventDetails<T>) => void) => VoidFunction -
onResponse (cacheKey: string, callback: (response: ClientResponseType<ResponseType, ErrorType>, details: CommandResponseDetails) => void) => VoidFunction -
onResponseById (requestId: string, callback: (response: ClientResponseType<ResponseType, ErrorType>, details: CommandResponseDetails) => void) => VoidFunction -
onResponseStart (queueKey: string, callback: (details: CommandEventDetails<T>) => void) => VoidFunction -
onResponseStartById (requestId: string, callback: (details: CommandEventDetails<T>) => void) => VoidFunction -
onUploadProgress (queueKey: string, callback: (values: FetchProgressType, details: CommandEventDetails<T>) => void) => VoidFunction -
onUploadProgressById (requestId: string, callback: (values: FetchProgressType, details: CommandEventDetails<T>) => void) => VoidFunction -

builder.commandManager.events.onResponse((response, details) => {
// ...
});

LoggerManager


LoggerManager is the main instance of the logging system in hyper-fetch. On its basis, we initiate single loggers in subsystems that are used in isolation, but still have access to the parent configuration in the builder.

const logger = builder.loggerManager.init("My Module")

logger.error(...) // output in console => [My Module] Some message