@sajari/sdk-react
Version:
React SDK for the Sajari API
28 lines (27 loc) • 1.06 kB
TypeScript
export declare type CallbackFn = (...args: any[]) => void;
export declare type UnlistenFn = () => void;
export declare type ListenerMap = Map<string, Listener>;
export declare class Listener {
private listeners;
/**
* Constructs a listener object.
*/
constructor();
/**
* Adds a callback to the listener.
* Returns a function that will unregister the callback from the listener when called.
* @param callback The callback to be registered.
* @return The unregister function to remove the callback from the listener.
*/
listen(callback: CallbackFn): UnlistenFn;
/**
* Removes a callback from the listener.
*/
unlisten(callback: CallbackFn): void;
/**
* Notify takes a function and calls it for every listener.
* The listener is supplied as the first argument to the function.
* @param {function(callback: Function)} fn Function to call each of the callbacks in the listener with.
*/
notify(fn: (callback: CallbackFn) => void): void;
}