Conform your JSON to ECMAScript 4 with JCON

Oliver Steele is doing great work, and he has just released a gem called JCON which stands for JavaScript Conformance. It tests JSON values to make sure that they are valid for the new world of ECMAScript 4 type definitions (e.g. new ( 3, "foo" ) )...

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 >