Skip to content

configure dispatcher

Massimo Giambona edited this page Mar 1, 2021 · 1 revision

You can configure the dispatcher implementing the IDispatcher interface and setup the dispatcher property of mediatorSettings.

Customize the dispatcher

Below the IDispatcher interface to implement.

/**
 * The dispatcher interface
 * Implement this interface and call mediatrSettings.dispatcher at startup
 * for changing the container and resolution of instances
 * 
 * @export
 * @interface IDispatcher
 */
export default interface IDispatcher {
    /**
     * Get all notification handlers order by order field for the specified event name
     *
     * @param {string} eventName The event name for which to get handlers
     * @returns {DispatchInstance[]}
     * @memberof IDispatcher
     */
    getAll(eventName: string): DispatchInstance[];

    /**
     * Add a dispatch instance to the container
     *
     * @param {DispatchInstance} instance The instance to add
     * @memberof IDispatcher
     */
    add(instance: DispatchInstance): void;

    /**
     * Remove all handlers for the specific event name
     *
     * @param {string} eventName The event for which remove the handlers
     * @memberof IDispatcher
     */
    remove(eventName: string): void;

    /**
     * Clear all instances from the container
     *
     * @memberof IDispatcher
     */
    clear(): void;
}

Setup the mediatorSettings

// app.ts -> this can be defined at the beginning of the app
import settings from "@/models/settings";

settings.dispatcher = new MyDispatcher();

Notes

You can implement only the getAll and add methods, the remove and clear methods are never called from the lib they are for developing purpose only.