Friday, October 10th, 2008

Reinhardt: a Client-side Dispatch Framework

Category: Dojo

Kevin Dangoor of SitePen has introduced Reinhardt a dispatch engine on the client side:

A typical server-side web framework today includes three main components: a URL dispatching to some controller object scheme, a template engine, and a data mapping facility. Currently in Dojo, you’ll find that the latter two items already exist. dojox.dtl provides the first one, and provides the second.

Given that Dojo already offers an implementation of the Django template engine, and that regular expression-based URL dispatch was a good fit for our problem at hand, I decided to base our URL dispatch on the model provided by Django.

You can see an example using the framework which uses these patterns:


  1. var patterns = reinhardt.urldispatch.patterns("demo.code",
  2.   [/^list\/(\d*)$/, "showMovieList", ["year"]],
  3.   [/^search$/, "search"],
  4.   [/^movie\/(\d+)\/$/, "whatyear", ['id']],
  5.   [/^movie\/([\w ]+)\/$/, "whatyear", ["name"]],
  6.   [/^luke$/, "whatyear", [], {name: "Cool Hand Luke"}]
  7. );

To get this all going you do something like this:


  1. dojo.addOnLoad(
  2.   function() {
  3.     if (!patterns.dispatch()) {
  4.       renderContent("../../default.dtl",
  5.                     {movieCount: demo.database.movies.length});
  6.     }
  7.   }
  8. );
  10. function renderContent(templatename, variables) {
  11.   var template = new dojox.dtl.Template(new dojo.moduleUrl("demo",
  12.                                       templatename));
  13.   var context = new dojox.dtl.Context(variables);
  14.   dojo.byId("content").innerHTML = template.render(context);
  15.   pagecount++;
  16.   dojo.byId("pagecount").innerHTML = pagecount;
  17. }

Read the full article for details, and download the entire sample, for perusal.

Posted by Dion Almaer at 6:32 am
1 Comment

3.7 rating from 32 votes

1 Comment »

Comments feed TrackBack URI

That looks pretty cool, I shall indeed have a perusal of it shortly!

Comment by solarisedesign — October 10, 2008

Leave a comment

You must be logged in to post a comment.