<commit_before>﻿import {
    ArrayTools,
    IEventListenerCallback,
    IDefaultEventDispatcher,
    EventListenerHelperItemVO,
    AssociativeArray
} from "../../index";
import {EventsHelperTools} from "../tools/EventsHelperTools";

export class EventListenerHelper<EventType extends any = any> {
    protected listenerThis: any;

    protected listenersByTypeMap: AssociativeArray<EventListenerHelperItemVO<EventType>[]>;

    constructor(listenerThis?: any) {
        this.listenerThis = listenerThis;

        this.construction();
    }

    protected construction(): void {
        this.listenersByTypeMap = new AssociativeArray<EventListenerHelperItemVO<EventType>[]>();
    }

    public destruction(): void {
        this.removeAllListeners();
        this.listenerThis = null;
    }


    public addEventListener(dispatcher: IDefaultEventDispatcher<EventType>,
                            type: string,
                            listener: IEventListenerCallback): void {

        var tempListeners: EventListenerHelperItemVO<EventType>[] = this.getEventListeners(type);

        var tempListenerData: EventListenerHelperItemVO<EventType> = new EventListenerHelperItemVO<EventType>();
        tempListenerData.dispatcher = dispatcher;
        tempListenerData.type = type;
        tempListenerData.listener = listener.bind(this.listenerThis);
        tempListenerData.sourceListener = listener;
        tempListeners.push(tempListenerData);
        //
        // dispatcher.addEventListener(type, tempListenerData.listener);
        EventsHelperTools.addEventListener(
            dispatcher,<commit_msg>Making the "this" param mandatory.<commit_after>﻿import {
    ArrayTools,
    IEventListenerCallback,
    IDefaultEventDispatcher,
    EventListenerHelperItemVO,
    AssociativeArray
} from "../../index";
import {EventsHelperTools} from "../tools/EventsHelperTools";

export class EventListenerHelper<EventType extends any = any> {
    protected listenerThis: any;

    protected listenersByTypeMap: AssociativeArray<EventListenerHelperItemVO<EventType>[]>;

    constructor(listenerThis: any) {
        this.listenerThis = listenerThis;

        this.construction();
    }

    protected construction(): void {
        this.listenersByTypeMap = new AssociativeArray<EventListenerHelperItemVO<EventType>[]>();
    }

    public destruction(): void {
        this.removeAllListeners();
        this.listenerThis = null;
    }


    public addEventListener(dispatcher: IDefaultEventDispatcher<EventType>,
                            type: string,
                            listener: IEventListenerCallback): void {

        var tempListeners: EventListenerHelperItemVO<EventType>[] = this.getEventListeners(type);

        var tempListenerData: EventListenerHelperItemVO<EventType> = new EventListenerHelperItemVO<EventType>();
        tempListenerData.dispatcher = dispatcher;
        tempListenerData.type = type;
        tempListenerData.listener = listener.bind(this.listenerThis);
        tempListenerData.sourceListener = listener;
        tempListeners.push(tempListenerData);
        //
        // dispatcher.addEventListener(type, tempListenerData.listener);
        EventsHelperTools.addEventListener(
            dispatcher,
{'fraction_non_alphanumeric': 0.09046153846153847, 'fraction_numerical': 0.0, 'mean_word_length': 3.2889182058047495, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '4622158', 'n_tokens_mistral': 790, 'n_tokens_neox': 776, 'n_words': 145}