Alexandru has posted 1 posts at DZone. View Full User Profile

New open source project: Strongly-Typed Javascript (STJS).

11.12.2011
| 1373 views |
  • submit to reddit

The subject is not new (GWT is there for a while already). Strongly –typed languages seem to keep being interesting in a developers’ world very attracted currently by dynamic, weakly typed languages. Dart is also another example. We believe that for bigger Javascript projects (let’s say more than 2000 lines of code), the Javascript becomes very hard to maintain, almost impossible to refactor. And even though the IDEs support for Javascript is increasing, it’s still way behind the one for Java. Try renaming a function in a Javascript project (one that has the same name as other function that you don’t want to rename)!


GWT seemed to be the ideal solution, but as with any development project, it’s very hard to satisfy everybody!  We don’t believe in big frameworks, all-in-one approach. We prefer smaller library focused on a single thing, that integrates nicely with other libraries that excel in their domain.
Our open source project “Strongly-typed Javascript” (STJS) focuses only on that part – generate the Javascript code from a Java code. We took Java as the input language as our server-side is written also in Java. So it becomes easier to share objects between client and server (via AJAX for example).


The project is provided as a Maven plugin that is executed after the Java sources of your project are compiled. Using the Maven-Eclipse integration you can also have the Javascript generated right after the input Java source file is saved (no need to re-build the project). This makes the developing roundtrip very short and it allows you to see the changes with a simple refresh of the page.
Our main concern when we built the library was to stay as close as possible to the initial code. Very few things are modified between the Java source and its Javascript counterpart. When debugging in a browser it’s cool to see a meaningful code! Here is a short example:
Java:

form.find(".ok").click(new EventHandler() {
  public boolean onEvent(Event evt, Element THIS) {
    $(that.row(stockData)).appendTo("table tbody");
    return true;
  }
});

Javascript:
form.find(".ok").click(function(evt) {
  $(that.row(stockData)).appendTo("table tbody");
  return true;
});

As you could figure out from the example, we don’t propose our GUI components - JQuery and the community around it do already a great job. We only built a bridge that allows you to use JQuery and JQuery UI plugins directly in the Java code.

If you’re interested in our project, feel free to have a look on the project’s web site http://st-js.sourceforge.net, give it a try and don’t hesitate to send us your feedback.
0
Published at DZone with permission of its author, Alexandru Craciun.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Attila Király replied on Wed, 2011/11/16 - 1:56pm

Any plan on releasing this to maven central repo?

Alexandru Craciun replied on Thu, 2011/11/17 - 3:03am in response to: Attila Király

Yes we planned that already. We'll try to deploy the next release on Maven central repository.

Alexandru Craciun replied on Thu, 2011/11/24 - 1:45pm

The release 1.1.3 has been deployed to Maven central repo. Please be aware that the groupId changed from org.stjs to org.st-js - to comply with Sonatype's requirements regarding the web domain owner (we have no affiliation with the http://stjs.org website :) )

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.