UNPKG

state-manager-utility

Version:
92 lines (91 loc) 3.64 kB
/** * SubscribedEvent will store all events that are currently being subscribed to and * actively looking into the same. * Format => {[event]: [{ callback: () => void }]} */ type CallbackMeta = { event: string; extraParams: any; }; type CallbackFn = (payload?: any, meta?: CallbackMeta) => void; /** * Event Broadcaster method * Event can be broadcasted without storing it into the state or temporarily. * * Expects event and data to be broadcasted. * * @param {string} event - unique identifier of event * @param {any} data - to be broadcasted * @param {boolean} isMemoryStore (optional) - if set to true, events will be persisted even after the current session (for this to work, initialization of local storage util is required) * @param {boolean} isTemp (optional) - determines if the event is to be broadcasted only one time * @param {boolean} dontTransmit (optional) - event will be stored with the data but won't be broadcasted immediately after update */ export declare function EmitEvent({ event, data, isMemoryStore, isTemp, dontTransmit, }: { event: string; data: any; isMemoryStore?: boolean; isTemp?: boolean; dontTransmit?: boolean; }): void; /** * Returns data without subscribing to the event. * @param {string} event - unique identifier of event * @param {boolean} isMemoryStore - default (false) - if set to true, events will be persisted even after the current session */ export declare function GetBroadcasterData({ event, isMemoryStore, }: { event: string; isMemoryStore?: boolean; }): { success: true; response: any; } | { success: false; }; /** * Removes event detail from the store, hence any listener won't be able to get updates * @param {string} event - unique identifier of event * @param {boolean} isMemoryStore - default (false) - if set to true, events will be persisted even after the current session (for this to work, initialization of local storage util is required) */ export declare function DeleteEvent({ event, isMemoryStore, }: { event: string; isMemoryStore?: boolean; }): void; /** * Event listener method * Calls back on event creation or updation * @param {string} event - unique identifier of event * @param {function} callback - callback function is invoked to pass on the event data * @param {any} extraParams - carry forward as it is while calling back * @param {boolean} isMemoryStore - default (false) - if set to true, events will be persisted even after the current session (for this to work, initialization of local storage util is required) * @param {boolean} isTemp (optional) - determines if the event is to be broadcasted only one time * @param {boolean} skipOldEvent - default (false) - if set to true, events will be persisted even after the current session */ export declare function SubscribeToEvent({ event, callback, extraParams, isMemoryStore, isTemp, skipOldEvent, }: { event: string; callback: CallbackFn; extraParams?: any; isMemoryStore?: boolean; isTemp?: boolean; skipOldEvent?: boolean; }): void; /** * Unsubscribe event from listening * @param {string} event * @param {function} callback * @param {boolean} isMemoryStore */ export declare function UnsubscribeEvent({ event, callback, isMemoryStore, }: { event: string; callback: CallbackFn; isMemoryStore?: boolean; }): void; /** * To check if anyone is subscribed to the given event * @param {string} event * @param {boolean} isMemoryStore */ export declare function HasEventSubscribed({ event, isMemoryStore, }: { event: string; isMemoryStore?: boolean; }): boolean; export {};