     @afterSubscribe?()
 
 
+  # Public: Associates an event name with a function to perform only once.
+  #
+  # eventName - A {String} name identifying an event
+  # handler - A {Function} that's executed when the event is triggered
   one: (eventName, handler) ->
     oneShotHandler = (args...) =>
       @off(eventName, oneShotHandler)

_ = require 'underscore'

module.exports =
  on: (eventName, handler) ->
    [eventName, namespace] = eventName.split('.')



    @afterUnsubscribe?() if @subscriptionCount() < subscriptionCountBefore

  # Public: When called, stops triggering any event.
  pauseEvents: ->
    @pauseCount ?= 0
    if @pauseCount++ == 0
      @queuedEvents ?= []

  # Public: When called, resumes triggering events.
  resumeEvents: ->
    if --@pauseCount == 0
      queuedEvents = @queuedEvents
      @queuedEvents = null
      @trigger(event...) for event in queuedEvents

  # Public: Identifies how many events are registered.
  #
  # Returns a `number`.
  subscriptionCount: ->
    count = 0
    for name, handlers of @eventHandlersByEventName
