UNPKG

2.04 kBTypeScriptView Raw
1import { AmplifyChannel, AmplifyEventData, EventDataMap, HubCallback, HubPayload, StopListenerCallback } from './types';
2export declare const AMPLIFY_SYMBOL: symbol;
3export declare class HubClass {
4 name: string;
5 private listeners;
6 protectedChannels: string[];
7 constructor(name: string);
8 /**
9 * Used internally to remove a Hub listener.
10 *
11 * @remarks
12 * This private method is for internal use only. Instead of calling Hub.remove, call the result of Hub.listen.
13 */
14 private _remove;
15 /**
16 * Used to send a Hub event.
17 *
18 * @param channel - The channel on which the event will be broadcast
19 * @param payload - The HubPayload
20 * @param source - The source of the event; defaults to ''
21 * @param ampSymbol - Symbol used to determine if the event is dispatched internally on a protected channel
22 *
23 */
24 dispatch<Channel extends AmplifyChannel>(channel: Channel, payload: HubPayload<AmplifyEventData[Channel]>, source?: string, ampSymbol?: symbol): void;
25 dispatch(channel: string, payload: HubPayload, source?: string, ampSymbol?: symbol): void;
26 /**
27 * Used to listen for Hub events.
28 *
29 * @param channel - The channel on which to listen
30 * @param callback - The callback to execute when an event is received on the specified channel
31 * @param listenerName - The name of the listener; defaults to 'noname'
32 * @returns A function which can be called to cancel the listener.
33 *
34 */
35 listen<Channel extends AmplifyChannel>(channel: Channel, callback: HubCallback<Channel, AmplifyEventData[Channel]>, listenerName?: string): StopListenerCallback;
36 listen<EventData extends EventDataMap>(channel: string, callback: HubCallback<string, EventData>, listenerName?: string): StopListenerCallback;
37 private _toListeners;
38}
39export declare const Hub: HubClass;
40/**
41 * @internal
42 *
43 * Internal hub used for core Amplify functionality. Not intended for use outside of Amplify.
44 *
45 */
46export declare const HubInternal: HubClass;