Page 1 of 1

Why isn't there an event.type?

Posted: 03 Jan 2013, 02:41
by Devon
It'd be nice to have an event.type implemented into the API so that we have a little more control and flexibility on how we manage our events...
For example, event.type = SFS2X.SFSEvent.CONNECTION.

I forward my events to an observer to be handled by the application... However, as it is now, I have to create a specific function for each SFS event, modify the event object to include it's type, and then forward it to my observer.

Re: Why isn't there an event.type?

Posted: 03 Jan 2013, 09:33
by Lapo
Hi,
I am not sure if I understand this correctly. Having dedicated function calls for each event is already the best way to handle events.
Using a global observer would lead to this code:

Code: Select all

function handler(event)
{
	if(event.type == CONNECT)
		handleConnect(event)
	else if if(event.type == LOGIN)
		handleLogin(event)
	//...
}
Which bring us back from where we started, with an additional passage.