<commit_before>do (window = @, Elyssa = @Elyssa or= {}) ->
  'use strict'
  
  class Elyssa.EventMap
    eventMap = {}
    eventFunctions = {}
    
    constructor: ->
      eventMap = {}
      eventFunctions = {}
    
    validEvents: []
    on: (eventName, eventFunction) -> 
      if @validEvents.length > 0
        return if validEvents.indexOf(eventName) is -1
        
      eventMap[eventName] = eventFunction      
    off: (eventName) -> delete eventMap[eventName] if eventMap[eventName]
    
    trigger: (eventName, args...) -> eventMap[eventName].apply(@, args) if eventMap[eventName]<commit_msg>Updated Elyssa.Events to allow for repeatable and intervalled events<commit_after>do (window = @, Elyssa = @Elyssa or= {}) ->
  'use strict'
  
  class Elyssa.EventMap
    eventMap = {}
    eventFunctions = {}
   
    constructor: ->
      eventMap = {}
      eventFunctions = {}
    
    validEvents: []

    on: (eventName, eventFunction) ->
      return unless eventFunction

      if @validEvents.length > 0
        return if validEvents.indexOf(eventName) is -1
        
      eventMap[eventName] = 
        event: eventFunction
        id: -1
        type: ''
      
      @
    off: (eventName) -> 
      return unless eventName    

      if eventMap[eventName].type is 'once' or eventMap[eventName].type is 'repeat'
        window.clearInterval eventMap[eventName].id if eventMap[eventName].type is 'repeat'
        window.clearTimeout eventMap[eventName].id if eventMap[eventName].type is 'once'

      delete eventMap[eventName] if eventMap[eventName]

      @
    
    trigger: (eventName, args...) ->
      return unless eventName?

      if typeof eventName is 'object'
        {name, interval, repeat, context} = eventName
      else
        name = eventName

      # Set default values
      interval = 0 unless interval?
      repeat = false unless repeat?
      context = @ unless context?

      triggerFunction = ->
        eventMap[name].event.apply(context, args) if eventMap[name]

      if interval      
        if repeat
          eventMap[name].type = 'repeat'
          eventMap[name].id = window.setInterval triggerFunction, interval
        else
          eventMap[name].type = 'once'
          eventMap[name].id = window.setTimeout triggerFunction, interval
      else
        eventMap[name].type = 'direct'
        triggerFunction.call @

      @
{'fraction_non_alphanumeric': 0.10435875943000839, 'fraction_numerical': 0.002514668901927913, 'mean_word_length': 2.265389876880985, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '79999', 'n_tokens_mistral': 699, 'n_tokens_neox': 677, 'n_words': 171}