<commit_before>class Cable.SubscriberManager
  constructor: (@cable) ->
    @subscribers = {}

  add: (subscriber) ->
    {identifier} = subscriber
    @subscribers[identifier] = subscriber
    if @sendCommand("subscribe", identifier)
      @notify(subscriber, "connected")

  reload: ->
    for identifier, subscriber of @subscribers
      if @sendCommand("subscribe", identifier)
        @notify(subscriber, "connected")

  remove: (subscriber) ->
    {identifier} = subscriber
    @sendCommand("unsubscribe", identifier)
    delete @subscribers[identifier]

  notifyAll: (event, args...) ->
    for identifier, subscriber of @subscribers
      @notify(subscriber, event, args...)

  notify: (subscriber, event, args...) ->
    if typeof subscriber is "string"
      subscriber = @subscribers[subscriber]

    if subscriber
      subscriber[event]?(args...)

  sendCommand: (command, identifier) ->
    return true if identifier is Cable.PING_IDENTIFIER
    @cable.send({command, identifier})
<commit_msg>Add "initialized" notification<commit_after>class Cable.SubscriberManager
  constructor: (@cable) ->
    @subscribers = {}

  add: (subscriber) ->
    {identifier} = subscriber
    @subscribers[identifier] = subscriber
    @notify(subscriber, "initialized")
    if @sendCommand("subscribe", identifier)
      @notify(subscriber, "connected")

  reload: ->
    for identifier, subscriber of @subscribers
      if @sendCommand("subscribe", identifier)
        @notify(subscriber, "connected")

  remove: (subscriber) ->
    {identifier} = subscriber
    @sendCommand("unsubscribe", identifier)
    delete @subscribers[identifier]

  notifyAll: (event, args...) ->
    for identifier, subscriber of @subscribers
      @notify(subscriber, event, args...)

  notify: (subscriber, event, args...) ->
    if typeof subscriber is "string"
      subscriber = @subscribers[subscriber]

    if subscriber
      subscriber[event]?(args...)

  sendCommand: (command, identifier) ->
    return true if identifier is Cable.PING_IDENTIFIER
    @cable.send({command, identifier})

{'fraction_non_alphanumeric': 0.1285024154589372, 'fraction_numerical': 0.0, 'mean_word_length': 3.674943566591422, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '3224359', 'n_tokens_mistral': 604, 'n_tokens_neox': 571, 'n_words': 146}