#1118 Compiling to javascript

tcolar Mon 14 Jun 2010

I'm playing with FWT in the browser ... however there is something I'm not clear about.

All the examples in "web" and "js" don't seem to use the @js facet ... instead they seem to compile the scripts on the fly - which is cool to play with.

I'm guessing in a real world app I would not want to use that (compile on the fly) but instead used the @js facet to pre-compile the code, however I'm unclear on how to serve it using wisp - In other word how do I make my FWT compiled to javascript component a webmod.

So say I have a "Window" fwt component with other UI stuff in it, I want to compile it to javascript ... then I want to use wisp to server it.

Is there an example that actually does it that way ?

rfeldman Mon 14 Jun 2010

I don't believe such an example exists, but I will strongly second the desire to see one. I tried out the compile-on-the-fly example just to play around with it, but I'd really like to see an example of how to do it "the real way".

andy Mon 14 Jun 2010

If you use the js/demo script, you just need to make a few changes:

  • You can remove the file compile step
  • Must add your pod into the js src includes in the <head> tag
  • Change WebUtil.jsMain to point to your class

This is the key line:

WebUtil.jsMain(out, "myPod::MyClass.main")

See the docs for jsMain.

katox Tue 15 Jun 2010

As Andy noted it is sufficient to remove the auto-compilation step and serve your new js file exactly the same way as sys.js, gfx.js etc.

I did this for the first time but a development with the autocompilation step was so much faster that it made me want the opposite - not only js autocompilation but also pod reloading (hotswap) to be as easy.

tcolar Thu 17 Jun 2010

Also what exactly needs to be annotated with @Js ? Only the my "UI" classes, or "everything" used one way or another to display my page ?

Any doc/example of that ?

tcolar Thu 17 Jun 2010

And also does it log anywhere when it's not working ... like say a script isn't found or wasn't compiled to Js ?

katox Thu 17 Jun 2010

Classes that are used to display the page including data holders ... anything called from your js UI code on the client side.

A missing script would be probably logged on the server side (failed to serve a fan://.. request). If it is just not working you need to go to javascript console and check errors there - a developer tools plugin for ff or chrome5+ tools help a lot.

The only example so far is in example/js. I'm trying to do a more complete one but I'm kinda slow.

Login or Signup to reply.