EventEmitter

So everyone can listen.

This component works together with the EventListener component. 
This component distributed Events and data to all listeners, without having to know who is actually listening. 
When strict mode is disabled, any kind of Event can be emitted to listeners without having to define it. 

It is advised to instead define your events beforehand in the following format JSON-Format.
{
    "Event_Name" : {
        "arguments"     : [ "argument_name:argument_type" ],
        "optional"      : [ "argument_name:argument_type=default_value"]
    } 
}
This will be used by the Listener to construct boilerplate callbacks, so this is primarily for other peoples sake.

When strict mode is enabled, you might want to catch some of the Exceptions. The exceptions live within the Emitter-Object and the event_exceptions operator.
EventException
EventException
MissingArgument
ToManyArguments
WrongArgumentType

To make live a little Easier, you can also use two decorators exposed via the Decorators member. It offers a post_emit and a pre_emit. They will emit the wrapped functionname as an Event and for pre_emit all arguments and for post_emit the result of the function.
decorator = op("Emitter").Decorators

@decorator.pre_emit
def pre_test_function(foo):
	return foo.upper()

@decorator.post_emit
def post_test_function(foo):
	return foo.upper()
	
pre_test_function( "bar" ) # Emits "pre_test_function" with arguments "bar"

post_test_function( "bar" ) # Emits "post_test_function" with arguments "Bar"

You can now also attach the emitter to the extension of the component you are developing, so it is no longer necessary to listen to an emitter inside your component.
In the init method of your extension, with an Emitter living inside call
	def __init__(self, ownerComp):
		# The component to which this extension is attached
		self.ownerComp = ownerComp

		self.ownerComp.op("Emitter").Attach_Emitter( self )
You can now target the component this extension is attached to directly with an eventListener.

Parameters:
  • Strict : Enable strict mode to stop emitting events if they do now follow the guidelines presented by the definition.
  • Graceful Error : When enabled, Exceptions in the eventListeners will be catched to not hinder execution.

Methods:
  • Emit( Event_Name, argument_1, argument_2, argument_n..., optional_argument_n = optional_value ): Emits the event and passes all arguments to the receivers. If strict mode is enabled this will throw an exception.




Downloads: 1035

Created at: 5.3.2022

Uploaded: 4.11.2024
Fixed error in strictmode.
Download