ProtoRPG: Role Playing with Prototype

Sometimes you want Monday to be a Friday, so we have ProtoRPG, a role playing game written by Pierre Chassaing in JavaScript using Prototype and Script.aculo.us. Walk around, add to your inventory, and feel like you are playing your first RPG many ...

Declarative Syntax for Widgets Print E-mail
User Rating: / 0
PoorBest 

Jeff Watkins is updating his MVC library, Coherent, and is wondering if he should add declarative syntax for child widgets. Currently, you have to write a lot of init() setup code, but instead he would like to do something like:

JAVASCRIPT:
  1.  
  2. sample.MyWidget= Class.create(coherent.Widget, {
  3.  
  4.     init: function()
  5.     {},
  6.  
  7.     title: TextWidget('div.header em', {
  8.                 htmlKeyPath: '*.selection.title',
  9.  
  10.                 onclick: function(event)
  11.                 {
  12.                     ... handle clicking on the title ...
  13.                 },
  14.                 ... etc ...
  15.             }),
  16.  
  17.     nextButton: Widget('div.controls button.next', {
  18.                     onclick: function(event)
  19.                     {
  20.                         ... go to the next image ...
  21.                     }
  22.                 }),
  23.     ... etc ...
  24. });
  25.  

Just before calling init, the Widget framework should create sub-widgets for title and nextButton. For the title, its html binding would be connected to the key path selection.title from the outer widget. Additionally, a click handler would be created with the given method. The scope of the onclick method for title would be MyWidget rather than the actual TextWidget.

Using the new Selector library, you could create widgets based on any CSS query rather than just a direct descendant or ID. I don?t think there?s any need to have sub-widgets within the sub-widgets. If that?s what you?re looking for, you probably want to look at creating a widget rather than declaring the structure.

How does that look? Any advice for Jeff?


Read more at: http://feeds.feedburner.com/~r/ajaxian/~3/298420587/declarative-syntax-for-widgets.
 
< Prev   Next >