Sha256: 93d2c67063045dad9ffb02894840cc337a2a8da0d2626cef7f5bc69ecfcce5d0

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 KB

Contents

module EventAggregator
	# Public: A module you can include or extend to receive messages from
	# the event Aggregator system.
	#
	# Examples
	#
	#   class Foo
	# 		Include Listener
	# 		...
	# 		def initialize()
	# 			...
	# 			message_type_register( "foo", lambda{ puts "bar" } )
	# 		end
	# 		...
	#  	end
	#
	module Listener
		private
		# public: Use to add message types you want to receive. Overwirte existing callback when existing message type is given.
		#
		# message_type 	- A string indicating the message type you want to receive from the event aggregrator. Can actually be anything.
		# callback 		- The method that will be invoked every time this message type is received. Must have: callback.respond_to? :call #=> true
		#
		# Examples
		#
		#   message_type_register("foo", method(:my_class_method))
		#   message_type_register("foo", lambda { puts "foo" })
		#   message_type_register("foo", Proc.new { puts "foo" })
		#
		def message_type_register( message_type, callback )
			Aggregator.register( self, message_type, callback)
		end

		# Public: Used to remove a certain type of message from your listening types. Messages of this specific type will no longer
		# invoke any callbacks.
		#
		# message_type -A string indicating the message type you no longer want to receive.
		#
		# Examples
		#
		#   message_type_unregister("foo")
		#
		def message_type_unregister( message_type )
			Aggregator.unregister(self, message_type)
		end
	end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
event_aggregator-1.0.2 lib/event_aggregator/listener.rb
event_aggregator-1.0.1 lib/event_aggregator/listener.rb
event_aggregator-1.0.0.pre lib/event_aggregator/listener.rb