<commit_before>export default class Timer {
  constructor ({name, interval, currentTime}) {
    if(name == null){
      this.name = ''
    }else{
      this.name = name
    }

    this.interval = interval
    this.lastTime = currentTime
    this.callTime = 0

    this.listeners = new Set()
  }

  addListener (listener) {
    this.listeners.add(listener)
  }

  removeListener (listener) {
    this.listeners.delete(listener)
  }

  update (currentTime) {
    if(currentTime - this.lastTime >= this.interval) {
      this.callListeners()
      this.lastTime = currentTime
      this.callTime ++
      return
    }
  }

  callListeners () {
    var timeEvent = this.createTimeEvent()

    for (let listener of this.listeners) {
      var method = listener['on'+this.name+'Timer']
      method.call(listener, timeEvent)
    }
  }

  createTimeEvent () {
    return {time: this.callTime}
  }
}<commit_msg>docsit<commit_after>export default class Timer {
  /**
   * 
   * @param {string} name 
   * @param {int} interval in millis
   * @param {int} currentTime in millis
   */
  constructor ({name, interval, currentTime}) {
    if(name == null){
      this.name = ''
    }else{
      this.name = name
    }

    this.interval = interval
    this.lastTime = currentTime
    this.callTime = 0

    this.listeners = new Set()
  }

  /**
   * Adds new listener to be called when timer updates
   * 
   * @param {*} listener 
   */
  addListener (listener) {
    this.listeners.add(listener)
  }

  /**
   * Removes listener from listeners
   * 
   * @param {*} listener 
  */
  removeListener (listener) {
    this.listeners.delete(listener)
  }

  /**
   * Checks if enough time has passed for timer update, and if it has, updates
   * 
   * @param {*} currentTime 
   */
  update (currentTime) {
    if(currentTime - this.lastTime >= this.interval) {
      this.callListeners()
      this.lastTime = currentTime
      this.callTime ++
      return
    }
  }

  /**
   * Helper method for calling all of the listeners
   */
  callListeners () {
    var timeEvent = this.createTimeEvent()

    for (let listener of this.listeners) {
      var method = listener['on'+this.name+'Timer']
      method.call(listener, timeEvent)
    }
  }

  /**
   * Function that creates the time event to be given to listeners
   */
  createTimeEvent () {
    return {time: this.callTime}
  }
}
{'fraction_non_alphanumeric': 0.12072604474461798, 'fraction_numerical': 0.0008442380751371887, 'mean_word_length': 2.414985590778098, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5065948', 'n_tokens_mistral': 762, 'n_tokens_neox': 738, 'n_words': 179}