Fun with FunScript

FunScript is a compiler or better a transpiler, which converts F# code into JavaScript code.
I have not tried it much since the last couple of days and I’m really amazed how well it works.

I had really good expierences creating D3 charts but I wasn’t shure how well it works with AngularJS, with all his dependency mechanisms and “magic” behind the scenes.
So I thought I give it a try!

I came up with this DSL like syntax:

The DSL code looks like this (mainly it wraps the kinda ugly generated code):

It is still a bit clunky to use (mainly to get angular’s dependency injection to work) and it is far from completed, but at least a simple controller works!

The downsides of using FunScript to generate JavaScript code is the additional code generation step, it generates more verbose code than writing similar code in JavaScript and the debugging is chunky (but that’s a problem nearly every transpiler has). I don’t know of a source map file for the generated code, but maybe I’m missing something.

On the other side you can use this nice functional and composable code in places where I never thought it is possible to get it to work!

The sample project can be found here.

Tagged , , , ,

5 thoughts on “Fun with FunScript

  1. […] Fun with FunScript – Tobias Burger […]

  2. panesofglass says:

    Great post! While FunScript still doesn’t have source maps, WebSharper just announced source maps coming in v3. You might check that project out. The license also just changed to be a bit more permissive. http://websharper.com/

  3. Hello Tobi. I am trying to use a code from your FunScript sample to build a demo website for presentation about FunScript. But $scope doesn’t work.
    Could you help me to figure out what is wrong?

    • tobiburger says:

      Hi Alexey!
      Sorry, I completely forgot about your comment. Can you provide me a link to your sample? For my – admittedly – simple example it seems to work fine.

      Nevertheless, there is a new star in town, called fable (http://fsprojects.github.io/Fable/) which is the successor of funscript.
      There doesn’t exist any sample for angular yet, but there are samples for Vue.js (todomvc) and React in the sample folder (https://github.com/fsprojects/Fable/tree/master/samples/browser).
      I did not have a chance yet to get a deeper look at the project, but from what I’ve seen it sounds very impressive and very promising!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: