Angular Tutorial Rewritten to ClojureScript

Over the last few months I learned some more ClojureScript and I finally came back to Angular. First I followed their excellent tutorial. Then I decided to rewrite it to plain Clojure and ClojureScript, and it went pretty well.

I made one change on the go – rather than load JSON files directly from disk, it talks to a Ring-provided service.

Raw files are below:

All code is available at GitHub.

It’s almost a one-to-one rewrite from JavaScript. Compared to the original, it is pretty ugly – for two reasons. The first is that I wanted it to work with advanced Closure compiler, so I had to use explicit dependencies. The second is that there is a lot JavaScript interop.

Many of those issues can be mitigated with a glue layer. It is possible to write functions or macros that would automatically generate array syntax for functions with injected dependencies, create functions automatically converting arguments with clj->js, and provide a better replacement for $scope.property = function(...){...}.

I may do that later, but firstly I wanted to have a one-to-one replacement.

6 thoughts on “Angular Tutorial Rewritten to ClojureScript

  1. Hey, check out my clang project on github (https://github.com/pangloss/clang). It has reimplemented the $parse provider in Angular to parse ClojureScript expressions in the template. It also provides clang-repeat to do what ng-repeat does, but for ClojureScript’s data structures. Plus it has a handful of macros, etc to make controllers a little bit nicer to write, too.

    It works great already, and I think it would be beneficial for everyone if people interested in this would combine efforts on one project. By the way, join the ClojureScript google group!

    Cheers,
    Darrick

  2. Tom – I looked at the abstract, and this is something I’ve been looking for for a long time. Any chance to see the slides or even recording of the talk?

  3. Yep, I’ll be uploading both the slides and angular tutorial code in the next week and will ping you when they’re up (there will eventually be a video of the recording, but I don’t know the schedule for that). Would welcome any feedback on this interop library if you subsequently try it out.

  4. Tom – thanks, that looks awesome. What is the catch?

    Any chance to use mrhyde independently, i.e. without introducing a dependency on strokes?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam protection by WP Captcha-Free