@versatiledatakit/shared
Version:
Versatile Data Kit Shared library enables reusability of shared features like: NgRx Redux, Error Handlers, Utils, Generic Components, etc.
60 lines (59 loc) • 2.43 kB
TypeScript
import { SystemEvent } from '../event';
/**
* ** System Event Dispatcher.
*
* - This Class is start point to trigger SystemEvent.
* - SystemEvent identifier is in string format, and would be nice those string to be assigned to constant for easier usage.
* - Payload could be any format but preferable is Literal Object.
* - SystemEvents could be dispatched in two ways using implemented behavior:
*
* 1) POST - this is NON-BLOCKING execution that leverages `setTimeout(handler, 0)` to avoid blocking main JavaScript thread.
*
* 2) SEND - this is BLOCKING execution that leverages `Promise` mechanism to chain Handlers execution. At the end returns
* flow of execution to Invoker.
*
* - Handlers and their usage read at Decorators JSDoc {@link SystemEventHandlerClass} {@link SystemEventHandler}.
*
* @see SystemEventDispatcher.post
* @see SystemEventDispatcher.send
*
* @example
* // void
* SystemEventDispatcher
* .post('SE_Send_Email', { email: 'taurus-shared@vmware.com });
*
* // returns Promise
* SystemEventDispatcher
* .send('SE_Create_Job', { jobName: 'Test', jobCreator: 'System' })
* .then((v) => {
* // Do something
* });
*/
export declare class SystemEventDispatcher {
/**
* ** Method to post System Event.
*
* - NON-BLOCKING execution.
* - Execution is non-blocking, e.g. it is executed in queue using setTimeout of 0.
* - If third parameters is provided it will execute as many handlers as it is request.
* - e.g. 1 or 2 or N and will skip the others.
*/
static post(eventId: SystemEvent, payload: any, handlersToExecute?: number): void;
/**
* ** Method to send System Event.
*
* - BLOCKING execution.
* - Execution is blocking, e.g. it is achieved using Promises, and every handler must return Promise.
* - If third parameters is provided it will execute as many handlers as it is request.
* - e.g. 1 or 2 or N and will return the flow to the invoker.
*/
static send(eventId: SystemEvent, payload: any, handlersToExecute?: number): Promise<boolean>;
/**
* ** Execute send command and handle Promises from handlers.
*/
private static executeSendCommand;
/**
* ** Execute Expression filter for Handler before execution.
*/
private static executeExpressionFilter;
}