login - help - about
?
header
<< Back to News

Web javascript libraries undergoing overhaul
I'm lazily refactoring many of javascript libraries within the web framework. The three main javascript libraries are
  • /js/org.benow.util.Util.js: miscellaneous frequently used utilities. Included in any dynamic page (*.page)
  • /js/org.benow.util.DOM.js: utilities associated with DOM objects (Elements, Documents, etc)
  • /js/org.benow.util.Request.js: ajax request/response handler used for calling services
The util functions are being moved into a Util object and as prototypes. For example, util_log(msg) which logs to the firebug log, if present, is now Util.log(msg). The scoping avoids function name collision. Some common methods are prototyped. For example addClass(elem,aClass), which adds a class to the class attribute of an element, is now [Element].addClass(aClass) and can be called directly, elem.addClass(aClass).

Element and document prototyping is taken further in og.benow.util.DOM.js. The getByPath(node,'/some/xsl/@path') has been prototyped to the node, such as [Element|Document].getByPath(path). This makes the code much cleaner node.getByPath('/some/xsl/@path'). The DOM utils are now even better for easily working with in memory DOM objects. Another nice change is the migration of DOM_toString(doc), which now returns an XML string via doc.toString().

The refactorings also work quite well with the Eclipse javascript plugin, which I'm really starting to like. I'm moving towards using a javascript documenter (like javadoc for javascript) in the build process, so that javascript libraries can be easily discovered and reused by developers. Hopefully I'll be able to move forward with plans to create dev jars, which contain packaged documentation and dynamically plug into the web development functionality.

I've also modified the javascript generator for services. This is the thing that generates javascript for ajax calls of java service methods. The generated javascript is now scoped. For example, a call to org.benow.ripper.RipperService.getAlbum(String):Album is now done via RipperService.getAlbum(string) (instead of getAlbum(string)). This will lessen name collisions.

I've seen this already, with DiscogsService and MusicBrainzService, which both have a getRelease(string) method. Previously the hacky response was to name the methods differently, but now they can have the same name and be referenced by class: MusicBrainzService.getRelease(key) and DiscogsService.getRelease(key).

The javascript transition is being done gradually. All replaced functions still exist, but are marked via Util.deprecated(reason). There is still much more that could be done with objectifying javascript libraries, and there will be more changes in time.

- 09:16 PM, 30 Mar 2011