<commit_before>'use strict';

module.exports = {
  componentWillMount: function() {
    this.listeners = this.listeners || [];
  },
  componentWillUnmount: function() {
    this.listeners.forEach(function(l){
      this.removeListener(l.ee, l.event, l.listener);
    }, this);
    this.listeners = [];
  },
  listenTo: function(ee, event, listener) {
    this.listeners = this.listeners || [];

    // wrap to avoid binding
    var newListener = function(){
      listener();
    };
    this.listeners.push({
      ee: ee,
      event: event,
      listener: newListener
    });
    ee.on(event, newListener);
    return this;
  },
  removeListener: function(ee, event, listener) {
    this.listeners = this.listeners || [];

    // TODO: remove from listeners if it exists
    // to prevent infinite buildup
    if (typeof ee.off === 'function') {
      ee.off(event, listener);
    } else if (typeof ee.removeListener === 'function') {
      ee.removeListener(event, listener);
    }
    return this;
  }
};<commit_msg>new listento stuff<commit_after>'use strict';

module.exports = {
  componentWillMount: function() {
    this._initializeListeners();
  },
  componentWillUnmount: function() {
    this.removeListeners();
  },

  _initializeListeners: function() {
    if (this.listeners) {
      return;
    }
    this.listeners = [];
  },

  listenTo: function(ee, event, listener) {
    this._initializeListeners();

    // wrap to avoid binding
    var newListener = function(){
      listener();
    };
    this.listeners.push({
      ee: ee,
      event: event,
      listener: newListener
    });
    ee.on(event, newListener);
    return this;
  },
  removeListeners: function() {
    if (!this.listeners) {
      return;
    }
    this.listeners.forEach(function(l){
      this.removeListener(l.ee, l.event, l.listener);
    }, this);
    this.listeners = null;
  },
  removeListener: function(ee, event, listener) {
    // TODO: remove from listeners if it exists
    // to prevent infinite buildup
    if (typeof ee.off === 'function') {
      ee.off(event, listener);
    } else if (typeof ee.removeListener === 'function') {
      ee.removeListener(event, listener);
    }
    return this;
  }
};
{'fraction_non_alphanumeric': 0.1437613019891501, 'fraction_numerical': 0.0, 'mean_word_length': 2.7318718381112985, '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': '909775', 'n_tokens_mistral': 687, 'n_tokens_neox': 678, 'n_words': 155}