Salient Solutions

wrasslin ones and nones for fun and profit - Sky Sanders' Blog
posts - 96, comments - 70, trackbacks - 0

Lightweight instrumented Javascript event model implementation

I have been doing a lot of javascript lately after a long time of not doing any javascript. I mean a long time and I found myself trying to implement patterns that have become familiar and trusted in the strongly typed class based OOP world.

I had some success but a lot of frustration, especially trying to enforce encapsulation to force the use of messages (events/delegate/commands etc).

I am sure there are very simple and elegant ways to to the things I have been trying to do but they were not in my rusty toolbox after so long.

What I really needed to build what I consider a robust application in any language is a delegate implementation that is intuitive and instrumented. I have had passing exposure, thankfully, to YUI and Google, and as I am sharpening my js chops, jQuery, but none of them really fit my needs. And the overhead involved with playing with MS Ajax, as so very cool 4.0 is, is just more than I can bear. I want infrastructure code that is lean, open and airy but strong as nails.

So it's time to implement an event model in javascript and then build a delegate implementation on top of it. I am not really concerned that there are implementations that almost suit my needs out there. I wanted to get back in shape, javascript-wise, and this looked to be the way to do it.

< insert 1 week of intense coding here >

Here it is. It works great and I can prove it. ;-) I am not a teacher and do not pretend to be. I write code, some would say, so I will let the code do the talking.

I have build a delegate implementation on top of this as well as an enhanced implementation of INotifyPropertyChange in js that work quite well. Will be posting those soon.

Find code and example http://skysanders.net/code/salientJs/event.aspx

 


Technorati tags:

Print | posted on Tuesday, July 14, 2009 6:56 AM |

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 7 and 2 and type the answer here:

Powered by: