Signals & Slots: an alternative to addEvent

Thursday, December 29, 2005

I've seen a lot of interest in perfecting the addEvent framework for javascript event listening. In these days of Ajax and Web2.0 there's been a lot of focus on these kinds of problems. I guess people are finding the inbuilt browser event APIs too limiting or cumbersome. Well, in these days of focusing on everything new, people often miss the old. Sometimes people have already tackled problems like this in previous years but I guess no one was paying much attention back then.

Regarding event frameworks, nothing new I've seen has matched the flexibility and simplicity of the signals and slots (sigslots) library from netWindows first released in 2002. Every other UI framework I have seen has focused on DOM event handling; the 'onxxxx' events of web page elements. The sigslots library, however, allows you to connect any two functions thus any function can become an event in your web page UI. Here's the magic:

 __sig__.connect(Object1, funcA_Name, Object2, funcB_Name);

There is much javascript mojo in that one line but essentially when Object1.functionA() is called then Object2.functionB() will also be called, passing the arguments supplied to the first function. Any 2 functions can be connected, including the traditional DOM event handlers. It has a bunch of other features as well like argument defaults, argument mutators, only connect once, disconnect all and so on.

Sigslots neatly abstracts your low level event handling into an anonymous messaging system between UI objects. And all in 9k! It's also compatible with any application that runs ECMAScript, not just browsers.

For further reading you can read about the Signals and Slots concept in traditional application programming an Alex Russell has written (back in 2002) an introduction the the sigslots javascript library.

No comments yet

Random outings from a chaotic mind

The Dexagogo Rocket Australian Web Industry Association logo

Delicious

Twitter