Sha256: 406360ea939d47907ae45376cba340df55ee66d0972f262f775783d3cdb3cdee

Contents?: true

Size: 772 Bytes

Versions: 3

Compression:

Stored size: 772 Bytes

Contents

module Faye
  module Publisher

    def count_listeners(event_type)
      return 0 unless @subscribers and @subscribers[event_type]
      @subscribers[event_type].size
    end

    def bind(event_type, &listener)
      @subscribers ||= {}
      list = @subscribers[event_type] ||= []
      list << listener
    end

    def unbind(event_type, &listener)
      return unless @subscribers and @subscribers[event_type]
      return @subscribers.delete(event_type) unless listener

      @subscribers[event_type].delete_if(&listener.method(:==))
    end

    def trigger(event_type, *args)
      return unless @subscribers and @subscribers[event_type]
      listeners = @subscribers[event_type].dup
      listeners.each { |listener| listener.call(*args) }
    end

  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
faye-0.8.11 lib/faye/mixins/publisher.rb
face-faye-0.8.9 lib/faye/mixins/publisher.rb
faye-0.8.9 lib/faye/mixins/publisher.rb