<commit_before>//= require "core"

(function() {
    // initialise variables
    var callbackCounter = 0;
    
    function getHandlers(target) {
        return target.obsHandlers;
    } // getHandlers

    function getHandlersForName(target, eventName) {
        var handlers = getHandlers(target);
        if (! handlers[eventName]) {
            handlers[eventName] = [];
        } // if

        return handlers[eventName];
    } // getHandlersForName

    /**
    # COG.observable
    */
    COG.observable = function(target) {
        if (! target) { return null; }

        /* initialization code */

        // check that the target has handlers 
        if (! getHandlers(target)) {
            target.obsHandlers = {};
        } // if

        var attached = target.bind || target.trigger || target.unbind;
        if (! attached) {
            target.bind = function(eventName, callback) {
                var callbackId = "callback" + (callbackCounter++);
                getHandlersForName(target, eventName).unshift({
                    fn: callback,
                    id: callbackId
                });

                return callbackId;
            }; // bind
            
            target.triggerCustom = function(eventName, args) {
                var eventCallbacks = getHandlersForName(target, eventName),
                    evt = {
                        cancel: false,
                        name: eventName
                    },
                    eventArgs;
                    
                // if we have arguments, then extend the evt object
                if (args) {
                    COG.extend(evt, args);
                } // if

                // check that we have callbacks
                if (! eventCallbacks) {
                    return null;
                } // if
            
                // get the event arguments without the event name
                eventArgs = Array.prototype.slice.call(arguments, 2);
                
                // if the target has defined an event interceptor (just one allowed)
                // then send it a capture of the event details
                if (target.eventInterceptor) {
                    target.eventInterceptor(eventName, evt, eventArgs);
                } // if<commit_msg>Fixed problem of not checking for own properties...<commit_after>//= require "core"

(function() {
    // initialise variables
    var callbackCounter = 0;
    
    function getHandlers(target) {
        return target.hasOwnProperty('obsHandlers') ? 
                target.obsHandlers : 
                null;
    } // getHandlers

    function getHandlersForName(target, eventName) {
        var handlers = getHandlers(target);
        if (! handlers[eventName]) {
            handlers[eventName] = [];
        } // if

        return handlers[eventName];
    } // getHandlersForName

    /**
    # COG.observable
    */
    COG.observable = function(target) {
        if (! target) { return null; }

        /* initialization code */

        // check that the target has handlers 
        if (! getHandlers(target)) {
            target.obsHandlers = {};
        } // if

        var attached = target.hasOwnProperty('bind');
        if (! attached) {
            target.bind = function(eventName, callback) {
                var callbackId = "callback" + (callbackCounter++);
                getHandlersForName(target, eventName).unshift({
                    fn: callback,
                    id: callbackId
                });

                return callbackId;
            }; // bind
            
            target.triggerCustom = function(eventName, args) {
                var eventCallbacks = getHandlersForName(target, eventName),
                    evt = {
                        cancel: false,
                        name: eventName,
                        source: this
                    },
                    eventArgs;
                    
                // if we have arguments, then extend the evt object
                if (args) {
                    COG.extend(evt, args);
                } // if

                // check that we have callbacks
                if (! eventCallbacks) {
                    return null;
                } // if
            
                // get the event arguments without the event name
                eventArgs = Array.prototype.slice.call(arguments, 2);
                
                // if the target has defined an event interceptor (just one allowed)
                // then send it a capture of the event details
                if (target.eventInterceptor) {
                    target.eventInterceptor(eventName, evt, eventArgs);
                } // if
{'fraction_non_alphanumeric': 0.09023511967803431, 'fraction_numerical': 0.0008472781190425757, 'mean_word_length': 1.2464319695528068, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2082862', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1080, 'n_words': 294}