Skip to main content
Version: 1.x.x

Managers

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


AppManager


This class is responsible for the application’s online or offline state and whether the application window is focused or blurred.

For example, suppose you want to use Hyper Fetch in a React Native environment and the default web browser events won't work. In that case, you need to set the events that are most optimal for the current environment.

info

Hyper Fetch event listeners return unmounting callbacks for easier cleanup handling.

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

...

unmountFocusListener()
unmountOfflineListener()

Events

{
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.

The CommandManager holds the cancellation tokens needed to terminate requests. It also manages tokens for events related to the request lifecycle, i.e. request start, upload, download, response, and abort.

info

Hyper Fetch event listeners return unmounting callbacks 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 request added to the dispatcher creates an abort controller for itself. This controller is stored in the Map object under abort key with the requestId. This lets you abort whole groups of requests using abortKey or single requests using their requestId. By default, abortKey is automatically created on command out of its endpoint and method, but you can set custom values.

Events

{
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 Hyper Fetch logging system. You can initiate single loggers based on it in subsystems; this allows you to isolate these loggers but still give them access to the parent configuration in the Builder.

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

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