<commit_before>var delegateListenerSplitter = /\S+/g;
var DLV = Backbone.View.extend({
    constructor: function(options) {
        options || (options = {});
        if (options.listeners) {
            this.listeners = options.listeners;
        }
        Backbone.View.apply(this, arguments);
        this.delegateListeners();
    },
    delegateListeners: function(listeners) {
        if (!(listeners || (listeners = _.result(this, 'listeners')))) {
            return this;
        }
        this.undelegateListeners();
        for (var key in listeners) {
            var method = listeners[key];
            if (!_.isFunction(method)) {
                method = this[listeners[key]];
            }
            if (!method) {
                continue;
            }
            var match = key.match(delegateListenerSplitter);
            var other = match.pop();
            other = (other === 'this') ? this : this[other];
            if (!other) {
                continue;
            }
            this.listenTo(other, match.join(' '), method);
        }
    },
    undelegateListeners: function() {
        for (var key in this.listeners) {
            var match = key.match(delegateListenerSplitter);
            var other = match.pop();
            other = (other === 'this') ? this : this[other];
            if (!other) {
                continue;
            }
            this.stopListening(other);
        }
    }
});<commit_msg>dry up delegate/undelegate listener methods<commit_after>var DLV = Backbone.View.extend({
    constructor: function(options) {
        options || (options = {});
        if (options.listeners) {
            this.listeners = options.listeners;
        }
        Backbone.View.apply(this, arguments);
        this.delegateListeners();
    },
    _implementListeners: function(listeners, implementation) {
        if (!(listeners || (listeners = _.result(this, 'listeners')))) {
            return;
        }
        for (var key in listeners) {
            var method = listeners[key];
            if (!_.isFunction(method)) {
                method = this[listeners[key]];
            }
            if (!method) {
                continue;
            }
            var match = key.match(/\S+/g);
            var other = match.pop();
            other = (other === 'this') ? this : this[other];
            if (!other) {
                continue;
            }
            this[implementation](other, match.join(' '), method);
        }
    },
    delegateListeners: function(listeners) {
        this._implementListeners(listeners, 'stopListening');
        this._implementListeners(listeners, 'listenTo');
        return this;
    },
    undelegateListeners: function() {
        this._implementListeners(this.listeners, 'stopListening');
        return this;
    }
});
{'fraction_non_alphanumeric': 0.1308974813763746, 'fraction_numerical': 0.0, 'mean_word_length': 1.714148219441771, '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': '837494', 'n_tokens_mistral': 747, 'n_tokens_neox': 743, 'n_words': 154}