<commit_before>/*  
[Check the tests](../test/Observer.html "Observer.html")  
________________________________________________________________________________________________
*/
define(function () { 'use strict';

    function Topic () {
        this._listeners = []
    }
    Topic.prototype = {
        createSubTopic : function (name) {
            this[name] = new Topic()
        },
        insertListener : function (subscriptionData) {
            var listeners = this._listeners,
                len = listeners.length,
                priority = subscriptionData.priority,
                added = false
            while (len--) {
                if (listeners[len].priority <= priority) {
                    listeners.splice(len + 1, 0, subscriptionData)
                    added = true
                    break
                }
            }
            if (!added) {
                listeners.unshift(subscriptionData)
            }
        },
        removeListener : function (callback) {
            var listeners = this._listeners,
                len = listeners.length,
                check
            if (typeof callback === 'function') {
                check = functionChecker
            } else if (typeof callback === 'string') {
                check = nameChecker
            } else if (typeof callback === 'object') {
                check = objectChecker
            } else {
                // if the user didn't pass a callback, all listeners will be removed
                check = passer
            }

            while (len--) {
                if (check(listeners[len])) {
                    listeners.splice(len, 1)
                }
            }

            function functionChecker (listenerData) {
                return listenerData.callback === callback
            }
            function nameChecker (listenerData) {
                return listenerData.callback.name === callback
            }
            function objectChecker (listenerData) {
                return listenerData === callback
            }
            function passer () {
                return true
            }
        }
    }

    function Subscription (context, callback, priority) {
        this.context = context
        this.callback = callback
        this.priority = priority<commit_msg>Moved checking functions outside removelistener<commit_after>/*  
[Check the tests](../test/Observer.html "Observer.html")  
________________________________________________________________________________________________
*/
define(function () { 'use strict';

    function Topic () {
        this._listeners = []
    }
    Topic.prototype = {
        createSubTopic : function (name) {
            this[name] = new Topic()
        },
        insertListener : function (subscriptionData) {
            var listeners = this._listeners,
                len = listeners.length,
                priority = subscriptionData.priority,
                added = false
            while (len--) {
                if (listeners[len].priority <= priority) {
                    listeners.splice(len + 1, 0, subscriptionData)
                    added = true
                    break
                }
            }
            if (!added) {
                listeners.unshift(subscriptionData)
            }
        },
        removeListener : function (callback) {
            var listeners = this._listeners,
                len = listeners.length,
                check
            if (typeof callback === 'function') {
                check = functionChecker
            } else if (typeof callback === 'string') {
                check = nameChecker
            } else if (typeof callback === 'object') {
                check = objectChecker
            } else {
                // if the user didn't pass a callback, all listeners will be removed
                check = passer
            }

            while (len--) {
                if (check(listeners[len])) {
                    listeners.splice(len, 1)
                }
            }

        }
    }
    
    function functionChecker (listenerData) {
        return listenerData.callback === callback
    }
    function nameChecker (listenerData) {
        return listenerData.callback.name === callback
    }
    function objectChecker (listenerData) {
        return listenerData === callback
    }
    function passer () {
        return true
    }

    function Subscription (context, callback, priority) {
        this.context = context
        this.callback = callback
        this.priority = priority
{'fraction_non_alphanumeric': 0.08735531775496834, 'fraction_numerical': 0.001310329766324525, 'mean_word_length': 1.4258474576271187, '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': '6562877', 'n_tokens_mistral': 1036, 'n_tokens_neox': 997, 'n_words': 259}