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.
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
Hi, nice post. I’ll be talking about this exact case (rewriting the angular tutorial in ClojureScript) tomorrow morning at the ClojureWest conference and will present a working solution that eliminates all of that clj->js JavaScript interop cruft.
http://clojurewest.org/sessions#white
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?
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.
Slides pending, but source code to the angular tutorial now posted:
https://github.com/dribnet/acute/
Also available as a live demo:
http://dribnet.github.com/acute/
Tom – thanks, that looks awesome. What is the catch?
Any chance to use mrhyde independently, i.e. without introducing a dependency on strokes?