<commit_before>/**
 * @author goliatone
 * @url https://github.com/goliatone/gpub
 * @copyright (c) 2013 goliatone
 * @license MIT
 * @title Gpub: Simple pub/sub
 * @overview Gpub is an Event Dispatcher library. Or pub/sub.
 * @module Gpub
 */
/*global define:true*/
/* jshint strict: false */
define('gpub', function() {
    ////////////////////////////////////////////////////////
    /// PRIVATE METHODS
    ////////////////////////////////////////////////////////
    var _publish = function(list, args, o) {
        var e, i = -1,
            l = list.length,
            a1 = args[0],
            a2 = args[1],
            a3 = args[2],
            _a = function(e) {
                o.event = e;
                o.target = e.target;
            };

        switch (args.length) {
            case 0:
                while (++i < l) {
                    e = list[i];
                    if (!e) continue;
                    _a(e);
                    if (e.callback.call(e.scope) === false) break;
                }
                return;
            case 1:
                while (++i < l) {
                    e = list[i];
                    if (!e) continue;
                    _a(e);
                    if (e.callback.call(e.scope, a1) === false) break;
                }
                return;
            case 2:
                while (++i < l) {
                    e = list[i];
                    if (!e) continue;
                    _a(e);
                    if (e.callback.call(e.scope, a1, a2) === false) break;
                }
                return;
            case 3:
                while (++i < l) {
                    e = list[i];
                    if (!e) continue;
                    _a(e);
                    if (e.callback.call(e.scope, a1, a2, a3) === false) break;
                }
                return;
            default:
                while (++i < l) {
                    e = list[i];
                    if (!e) continue;
                    _a(e);
                    if (e.callback.apply(e.scope, args) === false) break;
                }
                return;
        }
    };

    var _mixin = function(target, source) {

        if (typeof target === 'function') target = target.prototype;
        //TODO: Should we do Gpub.methods = ['on', 'off', 'emit', 'emits'];?
        Object.keys(source).forEach(function(method) {
            target[method] = source[method];
        });
        return target;
    };

    var _debounce = function(func, wait, immediate) {
        var timeout;
        return function() {
            var context = this,
                args = arguments;
            var later = function() {
                timeout = null;
                if (!immediate) func.apply(context, args);
            };
            var callNow = immediate && !timeout;
            clearTimeout(timeout);
            timeout = setTimeout(later, wait);
            if (callNow) func.apply(context, args);
        };
    };

    var _slice = [].slice;
    ////////////////////////////////////////////////////////
    /// CONSTRUCTOR
    ////////////////////////////////////////////////////////

    /**
     * Gpub is a simple pub sub library.
     * @class Gpub
     * @constructor
     */
    var Gpub = function() {};

    /**
     * Current VERSION
     */
    Gpub.VERSION = '0.3.5';


    ////////////////////////////////////////////////////////
    /// PUBLIC METHODS
    ////////////////////////////////////////////////////////

    /**
     * Register an event listener.
     * @param  {String}   topic    String indicating the event type
     * @param  {Function} callback Callback to handle event topics.
     * @param  {Object}   scope    We can dynamically change the scope of
     *                             the handler.
     * @param  {Object}   options  Options object that will be sent with the
     *                             event to all handler callbacks.
     * @return {this}
     */
    Gpub.prototype.on = function(topic, callback, scope, options) {
        //Create _callbacks, unless we have it
        var topics = this.callbacks(topic);

        //Create an array for the given topic key, unless we have it,
        //then append the callback to the array
        // topic.push(callback);
        var event = {};
        event.topic = topic;
        event.callback = callback;
        event.scope = scope || this;
        event.target = this;
        // event.options = options || {};//_merge((options || {}),{target:this});
        callback.__id__ = Gpub.uid();
        topics.push(event);

        return this;
    };
    var UID = 0;
    Gpub.uid = function() {
        return ++UID;
    };

    /**
     * Checks to see if the provided topic has
     * registered listeners and thus triggering
     * and event.
     * @param  {String} topic Event type.
     * @return {this}
     */
    Gpub.prototype.emits = function(topic) {

        return this.callbacks().hasOwnProperty(topic) && this.callbacks(topic).length > 0;
    };

    /**
     * Triggers an event so all registered listeners
     * for the `topic` will be notified.<commit_msg>Gpub: Added "multi" method<commit_after>/**
 * @author goliatone
 * @url https://github.com/goliatone/gpub
 * @copyright (c) 2013 goliatone
 * @license MIT
 * @title Gpub: Simple pub/sub
 * @overview Gpub is an Event Dispatcher library. Or pub/sub.
 * @module Gpub
 */
/*global define:true*/
/* jshint strict: false */
define('gpub', function() {
    ////////////////////////////////////////////////////////
    /// PRIVATE METHODS
    ////////////////////////////////////////////////////////
    var _publish = function(list, args, o) {
        var e, i = -1,
            l = list.length,
            a1 = args[0],
            a2 = args[1],
            a3 = args[2],
            _a = function(e) {
                o.event = e;
                o.target = e.target;
            };

        switch (args.length) {
            case 0:
                while (++i < l) {
                    e = list[i];
                    if (!e) continue;
                    _a(e);
                    if (e.callback.call(e.scope) === false) break;
                }
                return;
            case 1:
                while (++i < l) {
                    e = list[i];
                    if (!e) continue;
                    _a(e);
                    if (e.callback.call(e.scope, a1) === false) break;
                }
                return;
            case 2:
                while (++i < l) {
                    e = list[i];
                    if (!e) continue;
                    _a(e);
                    if (e.callback.call(e.scope, a1, a2) === false) break;
                }
                return;
            case 3:
                while (++i < l) {
                    e = list[i];
                    if (!e) continue;
                    _a(e);
                    if (e.callback.call(e.scope, a1, a2, a3) === false) break;
                }
                return;
            default:
                while (++i < l) {
                    e = list[i];
                    if (!e) continue;
                    _a(e);
                    if (e.callback.apply(e.scope, args) === false) break;
                }
                return;
        }
    };

    var _mixin = function(target, source) {

        if (typeof target === 'function') target = target.prototype;
        //TODO: Should we do Gpub.methods = ['on', 'off', 'emit', 'emits'];?
        Object.keys(source).forEach(function(method) {
            target[method] = source[method];
        });
        return target;
    };

    var _debounce = function(func, wait, immediate) {
        var timeout;
        return function() {
            var context = this,
                args = arguments;
            var later = function() {
                timeout = null;
                if (!immediate) func.apply(context, args);
            };
            var callNow = immediate && !timeout;
            clearTimeout(timeout);
            timeout = setTimeout(later, wait);
            if (callNow) func.apply(context, args);
        };
    };

    var _slice = [].slice;

    var _isArray = function(obj){
        return obj.push && obj.length != null;
    };

    ////////////////////////////////////////////////////////
    /// CONSTRUCTOR
    ////////////////////////////////////////////////////////

    /**
     * Gpub is a simple pub sub library.
     * @class Gpub
     * @constructor
     */
    var Gpub = function() {};

    /**
     * Current VERSION
     */
    Gpub.VERSION = '0.3.5';


    ////////////////////////////////////////////////////////
    /// PUBLIC METHODS
    ////////////////////////////////////////////////////////

    /**
     * Register an event listener.
     * @param  {String}   topic    String indicating the event type
     * @param  {Function} callback Callback to handle event topics.
     * @param  {Object}   scope    We can dynamically change the scope of
     *                             the handler.
     * @param  {Object}   options  Options object that will be sent with the
     *                             event to all handler callbacks.
     * @return {this}
     */
    Gpub.prototype.on = function(topic, callback, scope, options) {
        //Create _callbacks, unless we have it
        var topics = this.callbacks(topic);

        //Create an array for the given topic key, unless we have it,
        //then append the callback to the array
        // topic.push(callback);
        var event = {};
        event.topic = topic;
        event.callback = callback;
        event.scope = scope || this;
        event.target = this;
        // event.options = options || {};//_merge((options || {}),{target:this});
        callback.__id__ || (callback.__id__ = Gpub.uid());
        topics.push(event);

        return this;
    };

    /**
     * Attaches a single handler to multiple topics
     * @param  {String|Array}   topics   List of topics
     * @param  {Function} callback Handler
     * @param  {Object}   scope    Callback scope
     * @param  {Object}   options  Options object
     * @return {this}
     */
    Gpub.prototype.multi = function(topics, callback, scope, options){
        if(typeof topics === 'string') topics = topics.split(/\s/);
        if(! _isArray(topics)) return this.logger.error('Event types must be an array or a string with space delimited event types');

        topics.forEach(function(topic){
            this.on(topic, callback, scope, options);
        }, this);

        return this;
    };

    var UID = 0;
    Gpub.uid = function() {
        return ++UID;
    };

    /**
     * Checks to see if the provided topic has
     * registered listeners and thus triggering
     * and event.
     * @param  {String} topic Event type.
     * @return {this}
     */
    Gpub.prototype.emits = function(topic) {

        return this.callbacks().hasOwnProperty(topic) && this.callbacks(topic).length > 0;
    };

    /**
     * Triggers an event so all registered listeners
     * for the `topic` will be notified.
{'fraction_non_alphanumeric': 0.1754496402877698, 'fraction_numerical': 0.004676258992805755, 'mean_word_length': 1.1552325581395348, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5027681', 'n_tokens_mistral': 3040, 'n_tokens_neox': 2875, 'n_words': 834}