Sha256: d4f55433c33352b694ba71ab99bce3d1d27d3dfe9c4a851d6730d8ce65cc81bd
Contents?: true
Size: 876 Bytes
Versions: 2
Compression:
Stored size: 876 Bytes
Contents
require 'rubyfox/client/event' module Rubyfox module Client class EventHandler def initialize(smartfox) @handler = Hash.new { |hash, type| hash[type] = [] } @smartfox = smartfox end def register Event.types.each do |type| @smartfox.add_event_listener Event[type], self end end def unregister @smartfox.remove_all_event_listeners end def add(*names, &block) names.each do |name| type = Event[name] @handler[type] << block end end def remove(*names) names.each do |name| type = Event[name] @handler[type].clear end end def dispatch(event) type = event.type @handler[type].each do |handler| handler.call(event) end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rubyfox-client-0.1.0-java | lib/rubyfox/client/event_handler.rb |
rubyfox-client-0.0.1-java | lib/rubyfox/client/event_handler.rb |