Review: Yahoo Mojito gives server-side JavaScript a lift

Yahoo's open source framework combines YUI on the client, Node.js on the server, and excellent use of MVC design pattern

1 2 3 Page 2
Page 2 of 3

Each mojit has its own M, V, and C, which are written, more or less, in JSON, HTML/CSS, and JavaScript respectively. The biggest difference from other MVC approaches is that the model and controller are split into three parts. One part has code for the server, one part has code for the client, and the third has code for both. All three parts live next to each other, not in different stacks maintained by different people. I think this will be a great improvement for development teams because it breaks down the silos and frees us from the need to maintain people with different focuses.

The documentation suggests that Mojito is quite smart about this: "If your application is configured to deploy code to the client, Mojito will determine whether the client can execute JavaScript before deployment. If the client cannot execute JavaScript, your application code will instead execute on the server."

There aren't many details on how to exploit this, but structure is there for you to separate the code as you need. You have to be careful how you use the structure, and in the spirit of Node, you do the work on your own -- it's up to you to avoid any traps. A mojit on the server won't be able to manipulate a DIV on the client, for instance. It's worth noting that one recent project, Opa, promises to use the compiler to make automated decisions about where the code will run, but that level of hand-holding isn't provided here.

The Mojito framework is also designed to be smart about devices; to be more precise, it's designed to help you deliver different code to different devices. If your website visitor is using a smartphone, for example, the framework can dispense a different View built with a different template and a different set of local functions. This device sensitivity is essential these days, and the Mojito team was smart to build it into the framework itself.

YUI on the server

A big part of the framework is the Yahoo User Interface Library, known as YUI. This is a well-known and copiously documented collection of JavaScript tools that began life manipulating DIVs on the client. Now with Mojito, you'll be configuring your server-side Node application by calling the same YUI object. Most of your server-side JavaScript code will call YUI's add method to link your functions to events. The YUI is now doing heavy lifting on the server too.

Your Web application's events and much of its structure are defined by JSON files. I guess these are a step up from the endless opening and closing tags in frameworks like Struts that were built when XML was hip, but I quickly grew tired of hitting those quotation keys all of the time. Someone is bound to write a nice Web interface to these files so that we don't have to add so much glue punctuation. One version of my code crashed until I counted the curly brackets correctly, a task made easier by a parser that issued intelligent complaints about the mismatching.

Your affection for Mojito will depend on your affection for YUI. It's much simpler to use YUI widgets in the layout of your Web page because YUI is baked into all of the layers. This is largely a stylistic decision because the YUI has most of the functionality you might desire. It's fully formed and ready to go. The look and feel, though, may or may not be what you like. Some people assert that Yahoo Mail is the best out there, but others disagree. If you like Yahoo Mail, you'll probably be happy with what you create with Mojito.

The Mojito framework is also a good way for Yahoo to extend the reach of its APIs. It only takes a few lines of code to issue a call written in the Yahoo Query Language (YQL), the lingua franca for accessing Web databases like Flickr. The other parts of the Yahoo empire, including Yahoo Maps and Yahoo News, take the same style query. If you rely on any of these APIs, you'll be even more interested in Mojito.

1 2 3 Page 2
Page 2 of 3
How to choose a low-code development platform