-
Notifications
You must be signed in to change notification settings - Fork 0
jtlc and JXL Rationale
This project grew up from an effort to create an MVC architecture for Web applications around hierarchical, document-oriented data models shared between the client-side and the server-side layers. Early on, a disconnect was observed between the data representation that naturally expresses the relationships between objects of a data model and the requirements to data structure imposed by the visualization and UI components. Especially in the case of multiple views of the same data, the two are often hard to reconcile. Even with a single view, letting UI drive the design of the data model violates separation of concerns.
An obvious direct approach — writing increasingly complex Javascript expressions and loops to collect relevant data from the model as part of the view code — has 2 major disadvantages:
- It is code that has to be maintained, and it is impacted by every change in either the data model or the view so the simpler it is the better;
- Imperative code is not very expressive: it is hard to visualize the resulting data structures by looking at it. Keeping such an interface between the data schema and the HTML template makes the whole system that much harder to understand.
In short, a more explicit and compact declarative description — along the lines of XSLT — was desired to express data re-shaping operations.
- The JSON Query library provides XQuery-like functionality over Javascript data structures. It was evaluated and found to be falling short of the target from the standpoint of shaping the resulting data, In fact, JXL may be considered to build on top of JSON Query as the next layer of functionality;
- The JSLT library by Rik Arends. A very interesting contender that was, in the end, discarded, not least because the JSON Query syntax and capabilities were deemed superior. The data-shaping technique — structure of the output follows the structure of the template — was shamelessly borrowed from JSLT.
Two linked but conceptually independent entities have grown from this project:
- The jtlc (Javascript Template Language Compiler) — a framework for generating optimized Javascript code from an abstract syntax tree with semantics based on the dataflow processing model. The minimal amount of semantics that the framework directly provides can still be overridden and customized; the rest comes from an extensible collection of node classes or tags.
- The JXL (JSON Transformation Language) — a basic collection of tags that provides a comprehensive set of capabilities for querying and re-shaping JSON data (i.e. hierarchical collections of Javascript dictionaries and arrays).
The extensibility and freedom from a specific syntax make the combination of jtlc and JXL into a platform for building compiled template languages. And the underlying processing model provides significant expressive capability that, hopefully, makes the injection of handwritten Javascript code into templates largely superfluous.