<commit_before>// LICENSE : MIT
"use strict";
const assert = require("assert");
import CoreEventEmitter from "./CoreEventEmitter";
export const ON_WILL_EXECUTE_EACH_USECASE = "ON_WILL_EXECUTE_EACH_USECASE";
export const ON_ERROR = "ON_ERROR";
export const ON_DID_EXECUTE_EACH_USECASE = "ON_DID_EXECUTE_EACH_USECASE";

/**
 * payload The payload object that must have `type` property.
 * @typedef {Object} DispatcherPayload
 * @property {String} type The event type to dispatch.
 */
/**
 * Dispatcher is the **central** event bus system.
 *
 * also have these method.
 *
 * - onDispatch(payloadHandler): Function
 * - dispatch(payload): void
 *
 * Almost event pass the (on)dispatch.
 *
 * ## FAQ
 *
 * Q. Why use payload object instead emit(key, ...args).
 * A. It is for optimization and limitation.
 * If apply emit style, we cast ...args for passing other dispatcher at every time.
 */
export default class Dispatcher extends CoreEventEmitter {
    // Public global hook point
    /**
     * called the {@link handler} with useCase when the useCase will do.
     * @param {function(useCase: UseCase)} handler
     */
    onWillExecuteEachUseCase(handler) {
        return this.onDispatch(payload => {
            if (payload.type === ON_WILL_EXECUTE_EACH_USECASE) {
                handler(payload.useCase, payload.args);
            }
        });
    }

    /**
     * called the {@link handler} with useCase when the useCase is done.
     * @param {function(useCase: UseCase)} handler
     */
    onDidExecuteEachUseCase(handler) {
        return this.onDispatch(payload => {
            if (payload.type === ON_DID_EXECUTE_EACH_USECASE) {
                handler(payload.useCase);
            }
        });
    }

    /**
     * @deprecated
     **/
    onError() {
        throw new Error("rename to onErrorDispatch");
    }

    /**
     * add onAction handler and return unbind function
     * @param {Function} payloadHandler
     * @returns {Function} return unbind function
     * @override
     */
    onDispatch(payloadHandler) {
        return super.onDispatch(payload => {
            if (payload.type !== ON_WILL_EXECUTE_EACH_USECASE || payload.type !== ON_DID_EXECUTE_EACH_USECASE) {
                payloadHandler(payload);
            }
        });
    }

    /**
     * called the {@link errorHandler} with error when error is occurred.
     * @param {function(error: Error)} errorHandler
     * @returns {function(this:Dispatcher)}
     */
    onErrorDispatch(errorHandler) {
        return this.onDispatch(payload => {
            if (payload.type === ON_ERROR) {
                errorHandler(payload);
            }
        });
    }

    /**
     * dispatch the method when {@link useCase} will do.
     * @param {UseCase} useCase<commit_msg>refactor(dispatcher): remove unnecessary override method<commit_after>// LICENSE : MIT
"use strict";
const assert = require("assert");
import CoreEventEmitter from "./CoreEventEmitter";
export const ON_WILL_EXECUTE_EACH_USECASE = "ON_WILL_EXECUTE_EACH_USECASE";
export const ON_ERROR = "ON_ERROR";
export const ON_DID_EXECUTE_EACH_USECASE = "ON_DID_EXECUTE_EACH_USECASE";

/**
 * payload The payload object that must have `type` property.
 * @typedef {Object} DispatcherPayload
 * @property {String} type The event type to dispatch.
 */
/**
 * Dispatcher is the **central** event bus system.
 *
 * also have these method.
 *
 * - onDispatch(payloadHandler): Function
 * - dispatch(payload): void
 *
 * Almost event pass the (on)dispatch.
 *
 * ## FAQ
 *
 * Q. Why use payload object instead emit(key, ...args).
 * A. It is for optimization and limitation.
 * If apply emit style, we cast ...args for passing other dispatcher at every time.
 */
export default class Dispatcher extends CoreEventEmitter {
    // Public global hook point
    /**
     * called the {@link handler} with useCase when the useCase will do.
     * @param {function(useCase: UseCase)} handler
     */
    onWillExecuteEachUseCase(handler) {
        return this.onDispatch(payload => {
            if (payload.type === ON_WILL_EXECUTE_EACH_USECASE) {
                handler(payload.useCase, payload.args);
            }
        });
    }

    /**
     * called the {@link handler} with useCase when the useCase is done.
     * @param {function(useCase: UseCase)} handler
     */
    onDidExecuteEachUseCase(handler) {
        return this.onDispatch(payload => {
            if (payload.type === ON_DID_EXECUTE_EACH_USECASE) {
                handler(payload.useCase);
            }
        });
    }

    /**
     * @deprecated
     **/
    onError() {
        throw new Error("rename to onErrorDispatch");
    }
    
    /**
     * called the {@link errorHandler} with error when error is occurred.
     * @param {function(error: Error)} errorHandler
     * @returns {function(this:Dispatcher)}
     */
    onErrorDispatch(errorHandler) {
        return this.onDispatch(payload => {
            if (payload.type === ON_ERROR) {
                errorHandler(payload);
            }
        });
    }

    /**
     * dispatch the method when {@link useCase} will do.
     * @param {UseCase} useCase
{'fraction_non_alphanumeric': 0.11288439081354612, 'fraction_numerical': 0.0, 'mean_word_length': 2.591194968553459, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6228216', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1463, 'n_words': 408}