@sheerid/jslib-nightly
Version:
SheerID JavaScript Library
35 lines (34 loc) • 1.5 kB
TypeScript
import { Hook, HookEvents, RegisteredHooks } from '../types/types';
import { EventEmitter, EventArg } from './eventEmitter';
declare class Hooks extends EventEmitter<HookEvents> {
emit<K extends keyof HookEvents>(name: K, data: EventArg<HookEvents, K>): void;
}
/**
* This `hooks` object is the primary interaction point for listeners to events
* inside the jslib. It's `on`, `once` and `off` methods allow interaction with
* all `HookEvents`
*/
export declare const hooks: Hooks;
/**
* @description Register a callback function (a "hook") that will be called for a given hook name.
* Hook names are called at specific points during execution and allow some form of extensibility.
* @param hookName A specific string, one of the HookName type.
* @param callback The function to call when the system performs certain actions, described by the hook's name.
* @deprecated use `hooks.on()` instead
*/
export declare const addHook: (hook: Hook) => RegisteredHooks;
/**
* @description Retrieve a hook object that has been stored.
* @param hookName
* @deprecated
*/
export declare const getHook: <K extends keyof HookEvents>(hookName: K) => Function;
/**
* @description Look for an array of Hook objects that a developer may have provided in the window.sheerId object.
* If present, add each to the internal registry of hooks.
*
* @private
* @returns true if any hooks were successfully registered.
*/
export declare const addPredefinedHooks: () => boolean;
export {};