<commit_before># KDEventEmitter
# author : devrim - 12/27/2011
# refactored : sinan - 05/2012
# refactored : sinan - 01/2013

class KDEventEmitter
  @KDEventEmitterEvents = {}

  # listeners will be put inside @KDEventEmitterEvents[className]
  _e = @KDEventEmitterEvents[@name] = {}

  _on = (registry, eventName, callback)->
    # on can be defined before any emit, so create
    # the event registry, if it doesn't exist.
    registry[event] ?= []
    # register the listeners callback.
    registry[event].push callback

  _off = (registry, eventName, callback)->
    if event is "*"
      registry = {}
    # reset the listener container so no event
    # will be propagated to previously registered
    # listener callbacks.
    else if callback and registry[event]
      cbIndex = registry[event].indexOf callback
      registry[event].splice 1, cbIndex if cbIndex >= 0
    else
      registry[event] = []


  getEventParser = (event)->

    ///^
    #{event.replace(/\./g,'\\.').replace(/\*/g, '((?:\\w+\\.?)*)')}
    $///

  #
  # STATIC METHODS
  #####################
  # user is able to do ClassName.on .emit
  #

  @emit : ->
    # slice the arguments, 1st argument is the event name,
    # rest is args supplied with emit.
    [event, args...] = [].slice.call arguments
    # create listener container if it doesn't exist
    _e[event] ?= []
    # call every listener inside the container with the arguments (args)
    listener.apply null,args for listener in _e[event] if _e[event]?

  @on   :(event,callback)->  _on _e, event, callback
  @off  :(event, callback)-> _off _e, event, callback

  constructor:->
    @KDEventEmitterEvents  = {}
    @_e = @KDEventEmitterEvents[@constructor.name] = {}

  emit:(event, args...)->
    @_e[event] ?= []

    listenerStack = []

    for own eventName of @_e
      continue if eventName is event
      parser = getEventParser eventName
      if parser.test event
        listenerStack = listenerStack.concat @_e[eventName].slice(0)

    listenerStack = listenerStack.concat @_e[event].slice(0)

    listenerStack.forEach (listener)=>
      listener.apply @, args

  on  :(event, callback) -> _on  @_e, event, callback
  off :(event, callback) -> _off @_e, event, callback
  unsubscribe:(event, callback) -> _off @_e, event, callback

  once:(event, callback) ->
    _callback = () =>
      args = [].slice.call arguments
      @unsubscribe event, _callback
      callback.apply @, args

    @on event, _callback
<commit_msg>eventemitter fixed<commit_after># KDEventEmitter
# author : devrim - 12/27/2011
# refactored : sinan - 05/2012
# refactored : sinan - 01/2013

class KDEventEmitter
  @KDEventEmitterEvents = {}

  # listeners will be put inside @KDEventEmitterEvents[className]
  _e = @KDEventEmitterEvents[@name] = {}

  _on = (registry, eventName, callback)->
    # on can be defined before any emit, so create
    # the event registry, if it doesn't exist.
    registry[eventName] ?= []
    # register the listeners callback.
    registry[eventName].push callback

  _off = (registry, eventName, callback)->
    if eventName is "*"
      registry = {}
    # reset the listener container so no event
    # will be propagated to previously registered
    # listener callbacks.
    else if callback and registry[eventName]
      cbIndex = registry[eventName].indexOf callback
      registry[eventName].splice 1, cbIndex if cbIndex >= 0
    else
      registry[eventName] = []


  getEventParser = (event)->

    ///^
    #{event.replace(/\./g,'\\.').replace(/\*/g, '((?:\\w+\\.?)*)')}
    $///

  #
  # STATIC METHODS
  #####################
  # user is able to do ClassName.on .emit
  #

  @emit : ->
    # slice the arguments, 1st argument is the event name,
    # rest is args supplied with emit.
    [eventName, args...] = [].slice.call arguments
    # create listener container if it doesn't exist
    _e[eventName] ?= []
    # call every listener inside the container with the arguments (args)
    listener.apply null,args for listener in _e[eventName] if _e[eventName]?

  @on   :(eventName, callback)-> _on _e, eventName, callback
  @off  :(eventName, callback)-> _off _e, eventName, callback

  constructor:->
    @KDEventEmitterEvents  = {}
    @_e = @KDEventEmitterEvents[@constructor.name] = {}

  emit:(eventName, args...)->
    @_e[eventName] ?= []

    listenerStack = []

    for own eventToBeFired of @_e
      continue if eventToBeFired is eventName
      parser = getEventParser eventToBeFired
      if parser.test eventName
        listenerStack = listenerStack.concat @_e[eventToBeFired].slice(0)

    listenerStack = listenerStack.concat @_e[eventName].slice(0)

    listenerStack.forEach (listener)=>
      listener.apply @, args

  on  :(eventName, callback) -> _on  @_e, eventName, callback
  off :(eventName, callback) -> _off @_e, eventName, callback
  unsubscribe:(eventName, callback) -> _off @_e, eventName, callback

  once:(eventName, callback) ->
    _callback = =>
      args = [].slice.call arguments
      @unsubscribe eventName, _callback
      callback.apply @, args

    @on eventName, _callback

{'fraction_non_alphanumeric': 0.13304552590266877, 'fraction_numerical': 0.009811616954474097, 'mean_word_length': 3.04203013481364, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '1175810', 'n_tokens_mistral': 1635, 'n_tokens_neox': 1539, 'n_words': 458}