script.aculo.us Design Patterns
It probably needs a name. It works.
I didn’t think it would work at first. It appeared to want to create a parallel object model to the DOM, but now I see that it is about creating controllers.
Last I programmed in JavaScript, I’d used event bubbling extensively. Often I’d attach an event handler to a document root and filter messages based on class name. It was fast, and the pages were anyway quite uniform. They were large control trees, so this event handling made a lot of sense.
I started by creating static methods, and looking up data in the document. I’ve not switched to instanciating an object for a control, and keeping a instance copy of the participants. After this, the Prototype object implementation makes it easy to write event handlers.
I’ve also created an XSLT transform that emits HTML generation functions in JavaScript. It takes a cut down XML scripting language that is HTML with embedded commands and generates a JavaScript function that iterates over a JavaScript object to produce a string of HTML.
This could be converted to constructing an HTML or XML DOM. Should encoding problems arise, I can switch to a data model with well defined serialization.
When I add tag clouds, I’m going to use event blubbling, because I cannot imagine attaching an event handler to every tag in the cloud. I want to see if this is how Sortables are handled in dragdrop.js, or select items in Autocomplete.