UNPKG

@hyper-fetch/core

Version:

Cache, Queue and Persist your requests no matter if you are online or offline!

71 lines 3.9 kB
import { PluginMethodParameters, PluginMethods, PluginOptionsType } from '.'; import { ClientInstance } from '../client'; /** * Base class for plugins that hook into the request, cache, dispatcher, and adapter lifecycle. * Extend this to build devtools, logging, analytics, or custom side-effect plugins. */ export declare class Plugin<Client extends ClientInstance = ClientInstance, PluginData = void> { config: PluginOptionsType<PluginData>; name: string; data: PluginData; client: Client | undefined; private pluginMethods; constructor(config: PluginOptionsType<PluginData>); /** Bind the plugin to a client instance. Called automatically when the plugin is added via `client.addPlugin()`. */ initialize: (client: Client) => this; /** Invoke a registered plugin method by name. Used internally by the client to dispatch lifecycle events. */ trigger: <Key extends keyof PluginMethods<Client>>(method: Key, data: PluginMethodParameters<Key, Client>) => void; /** * Callback that will be executed when plugin is mounted */ onMount: (callback: PluginMethods<Client>["onMount"]) => this; /** * Callback that will be executed when plugin is unmounted */ onUnmount: (callback: PluginMethods<Client>["onUnmount"]) => this; /** * Callback that will be executed when request is created */ onRequestCreate: (callback: PluginMethods<Client>["onRequestCreate"]) => this; /** * Callback that will be executed when request gets triggered */ onRequestTrigger: (callback: PluginMethods<Client>["onRequestTrigger"]) => this; /** * Callback that will be executed when request starts */ onRequestStart: (callback: PluginMethods<Client>["onRequestStart"]) => this; /** * Callback that will be executed when response is successful */ onRequestSuccess: (callback: PluginMethods<Client>["onRequestSuccess"]) => this; /** * Callback that will be executed when response is failed */ onRequestError: (callback: PluginMethods<Client>["onRequestError"]) => this; /** * Callback that will be executed when response is finished */ onRequestFinished: (callback: PluginMethods<Client>["onRequestFinished"]) => this; /** Called when the dispatcher storage is fully cleared */ onDispatcherCleared: (callback: PluginMethods<Client>["onDispatcherCleared"]) => this; /** Called when a dispatcher queue has no more pending requests */ onDispatcherQueueDrained: (callback: PluginMethods<Client>["onDispatcherQueueDrained"]) => this; /** Called when a dispatcher queue transitions to running, paused, or stopped */ onDispatcherQueueRunning: (callback: PluginMethods<Client>["onDispatcherQueueRunning"]) => this; /** Called when a new item is added to a dispatcher queue */ onDispatcherItemAdded: (callback: PluginMethods<Client>["onDispatcherItemAdded"]) => this; /** Called when an item is removed from a dispatcher queue */ onDispatcherItemDeleted: (callback: PluginMethods<Client>["onDispatcherItemDeleted"]) => this; /** Called when a new dispatcher queue is created */ onDispatcherQueueCreated: (callback: PluginMethods<Client>["onDispatcherQueueCreated"]) => this; /** Called when an entire dispatcher queue is cleared */ onDispatcherQueueCleared: (callback: PluginMethods<Client>["onDispatcherQueueCleared"]) => this; /** Called when a cache entry is created or updated */ onCacheItemChange: (callback: PluginMethods<Client>["onCacheItemChange"]) => this; /** Called when a cache entry is deleted */ onCacheItemDelete: (callback: PluginMethods<Client>["onCacheItemDelete"]) => this; /** Called when the adapter fetcher is about to execute a request */ onAdapterFetch: (callback: PluginMethods<Client>["onAdapterFetch"]) => this; } //# sourceMappingURL=plugin.d.ts.map