<commit_before>/**
 * ##dispatcher##
 * Behavior modifier for event dispatching.
 * @param {Object} target - the object to apply the methods to.
 * @param {Object} scope - the object that the methods will be applied from
 * @param {object} map - custom names of what methods to map from scope. such as _$emit_ and _$broadcast_.
 */

define('dispatcher', ['apply'], function (apply) {

    function Event(type) {
        this.type = type;
        this.defaultPrevented = false;
        this.propagationStopped = false;
        this.immediatePropagationStopped = false;
    }
    Event.prototype.preventDefault = function() {
        this.defaultPrevented = true;
    };
    Event.prototype.stopPropagation = function() {
        this.propagationStopped = true;
    };
    Event.prototype.stopImmediatePropagation = function() {
        this.immediatePropagationStopped = true;
    };
    Event.prototype.toString = function() {
        return this.type;
    };

    var dispatcher = function (target, scope, map) {
        // if you try to make the same item a dispatcher, it will just do nothing.
        if (target && target.on && target.on.dispatcher) {
            return target;// it is already a dispatcher.
        }
        target = target || {};
        var listeners = {};

        /**
         * ###off###
         * removeEventListener from this object instance. given the event listened for and the callback reference.
         * @param event
         * @param callback
         */
        function off(event, callback) {
            var index, list;
            list = listeners[event];
            if (list) {
                if (callback) {
                    index = list.indexOf(callback);
                    if (index !== -1) {
                        list.splice(index, 1);
                    }
                } else {
                    list.length = 0;
                }
            }
        }

        /**
         * ###on###
         * addEventListener to this object instance.
         * @param {String} event
         * @param {Function} callback
         * @returns {Function} - removeListener or unwatch function.
         */
        function on(event, callback) {
            listeners[event] = listeners[event] || [];
            listeners[event].push(callback);
            return function () {
                off(event, callback);
            };
        }

        /**
         * ###once###
         * addEventListener that gets remove with the first call.
         * @param event
         * @param callback
         * @returns {Function} - removeListener or unwatch function.
         */
        function once(event, callback) {
            function fn() {
                off(event, fn);
                apply(callback, scope || target, arguments);
            }

            return on(event, fn);
        }

        /**
         * ###getListeners###
         * get the listeners from the dispatcher.
         * @param {String} event
         * @param {Boolean} strict
         * @returns {*}
         */
        function getListeners(event, strict) {
            var list, a = '*';
            if (event || strict) {
                list = [];
                if (listeners[a]) {
                    list = listeners[a].concat(list);
                }
                if (listeners[event]) {
                    list = listeners[event].concat(list);
                }
                return list;
            }
            return listeners;
        }

        function removeAllListeners() {
            listeners = {};
        }

        /**
         * ###fire###
         * fire the callback with arguments.
         * @param {Function} callback
         * @param {Array} args
         * @returns {*}
         */
        function fire(callback, args) {
            return callback && apply(callback, target, args);
        }

        /**
         * ###dispatch###
         * fire the event and any arguments that are passed.
         * @param {String} event
         */
        function dispatch(event) {
            var list = getListeners(event, true), len = list.length, i, event = new Event(arguments[0]);
            if (len) {
                arguments[0] = event;
                for (i = 0; i < len; i += 1) {
                    if (!event.immediatePropagationStopped) {
                        fire(list[i], arguments);
                    }
                }
            }
            return event;
        }

        if (scope && map) {
            target.on = scope[map.on] && scope[map.on].bind(scope);
            target.off = scope[map.off] && scope[map.off].bind(scope);
            target.once = scope[map.once] && scope[map.once].bind(scope);<commit_msg>fix - check if valid function in handler before adding to listeners<commit_after>/**
 * ##dispatcher##
 * Behavior modifier for event dispatching.
 * @param {Object} target - the object to apply the methods to.
 * @param {Object} scope - the object that the methods will be applied from
 * @param {object} map - custom names of what methods to map from scope. such as _$emit_ and _$broadcast_.
 */

define('dispatcher', ['apply', 'isFunction'], function (apply, isFunction) {

    function Event(type) {
        this.type = type;
        this.defaultPrevented = false;
        this.propagationStopped = false;
        this.immediatePropagationStopped = false;
    }
    Event.prototype.preventDefault = function() {
        this.defaultPrevented = true;
    };
    Event.prototype.stopPropagation = function() {
        this.propagationStopped = true;
    };
    Event.prototype.stopImmediatePropagation = function() {
        this.immediatePropagationStopped = true;
    };
    Event.prototype.toString = function() {
        return this.type;
    };

    function validateEvent(e) {
        if (!e) {
            throw Error('event cannot be undefined');
        }
    }

    var dispatcher = function (target, scope, map) {
        // if you try to make the same item a dispatcher, it will just do nothing.
        if (target && target.on && target.on.dispatcher) {
            return target;// it is already a dispatcher.
        }
        target = target || {};
        var listeners = {};

        /**
         * ###off###
         * removeEventListener from this object instance. given the event listened for and the callback reference.
         * @param event
         * @param callback
         */
        function off(event, callback) {
            validateEvent(event);
            var index, list;
            list = listeners[event];
            if (list) {
                if (callback) {
                    index = list.indexOf(callback);
                    if (index !== -1) {
                        list.splice(index, 1);
                    }
                } else {
                    list.length = 0;
                }
            }
        }

        /**
         * ###on###
         * addEventListener to this object instance.
         * @param {String} event
         * @param {Function} callback
         * @returns {Function} - removeListener or unwatch function.
         */
        function on(event, callback) {
            if(isFunction(callback)) {
                validateEvent(event);
                listeners[event] = listeners[event] || [];
                listeners[event].push(callback);
                return function () {
                    off(event, callback);
                };
            }
        }

        /**
         * ###once###
         * addEventListener that gets remove with the first call.
         * @param event
         * @param callback
         * @returns {Function} - removeListener or unwatch function.
         */
        function once(event, callback) {
            if(isFunction(callback)) {
                validateEvent(event);
                function fn() {
                    off(event, fn);
                    apply(callback, scope || target, arguments);
                }

                return on(event, fn);
            }
        }

        /**
         * ###getListeners###
         * get the listeners from the dispatcher.
         * @param {String} event
         * @param {Boolean} strict
         * @returns {*}
         */
        function getListeners(event, strict) {
            validateEvent(event);
            var list, a = '*';
            if (event || strict) {
                list = [];
                if (listeners[a]) {
                    list = listeners[a].concat(list);
                }
                if (listeners[event]) {
                    list = listeners[event].concat(list);
                }
                return list;
            }
            return listeners;
        }

        function removeAllListeners() {
            listeners = {};
        }

        /**
         * ###fire###
         * fire the callback with arguments.
         * @param {Function} callback
         * @param {Array} args
         * @returns {*}
         */
        function fire(callback, args) {
            return callback && apply(callback, target, args);
        }

        /**
         * ###dispatch###
         * fire the event and any arguments that are passed.
         * @param {String} event
         */
        function dispatch(event) {
            validateEvent(event);
            var list = getListeners(event, true), len = list.length, i, event = typeof event === 'object' ? event : new Event(event);
            if (len) {
                arguments[0] = event;
                for (i = 0; i < len; i += 1) {
                    if (!event.immediatePropagationStopped) {
                        fire(list[i], arguments);
                    }
                }
            }
            return event;
        }

        if (scope && map) {
            target.on = scope[map.on] && scope[map.on].bind(scope);
            target.off = scope[map.off] && scope[map.off].bind(scope);
            target.once = scope[map.once] && scope[map.once].bind(scope);
{'fraction_non_alphanumeric': 0.11446024434207891, 'fraction_numerical': 0.0013018225515722011, 'mean_word_length': 1.422265340771283, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6486269', 'n_tokens_mistral': 2535, 'n_tokens_neox': 2476, 'n_words': 688}