ATTENTION NOTE: I'm in the process of gradually updating the series. At the moment I updated the series up to the tutorial-07, while all the others are still using aged stuff. Please be patient because it will take at least a month to complete the work.
Modern ClojureScript (
modern-cljs) is a series of tutorials that guide you in
creating and running ClojureScript (CLJS) projects.
If you don't know anything about Clojure (or about Lisp), I recommend you learn a little bit before starting these tutorials.
There are plenty of outstanding resources on Clojure that are freely available on the Internet, and you can't overestimate the benefit of reading a book on Clojure (or another Lisp dialect) to your value as a programmer.
Here are some book recommendations:
- Clojure Programming: written by three of the heroes of Clojure, it contains everything you need to know about Clojure and its ecosystem.
- Programming Clojure: written by another legendary Clojure developer, it's the easiest path to learning Clojure.
- The Joy of Clojure: the title speaks by itself. A must read!
- SICP - Structure and Interpretation of Computer Programs: this is the best programming book I've read in my very long career. It uses Scheme/Racket (a Lisp dialect) rather than Clojure and is available online, in print, or in a lecture series.
- On Lisp: if you want to learn about macros, this is the place to start. It uses Common Lisp (a Lisp dialect) rather than Clojure.
Many people worry about which operating system and editor/IDE are best for developing in Clojure and ClojureScript. I personally use Mac OS X, Debian and Ubuntu. I use Emacs as an editor.
Because I'm an old-timer, *nix and Emacs are the OS and editor I know best. That being said, in this series of tutorials you're not going to find any suggestions or reference to operating systems or editors. Use whatever tools you already have and know. I have too much respect for people developing IDE/plugins for Clojure/CLJS to say that one is better than another, and you don't want to combine learning a new programming language with trying to learn a new programming environment.
Why the name Modern ClojureScript?
You might wonder why this tutorial series is named
ClojureScript is so recent. I started this series while trying to port
book to ClojureScript, and now it's too late to change.
This series of tutorials guides you in creating and running simple CLJS projects. The bulk of the series follows the progressive enhancement of a single project.
While working through the tutorials I strongly suggest you start at tutorial 1 and type in all the code for each tutorial yourself. In my experience this is the the best approach if you're not already very fluent with the programming language.
Create and configure a very basic CLJS project.
Set up a browser-connected CLJS REPL (bRepl) using an external http-server.
Use the Domina library to make our login form validation more Clojure-ish.
Investigate and find two different ways to solve an issue from the last tutorial.
Explore CLJS/CLS compilation modes by using the
lein-cljsbuild plugin of
leiningen, and discover a problem and solve it using a feature of the
Use Domina events for a more Clojure-ish approach to handing DOM events.
Programmatically manipulate DOM elements in response to DOM events.
Use AJAX to let the CLJS client-side code communicate with the server.
Apply Domina events to the login form example from the 4th Tutorial.
Explore the highest (HTML5) and deepest (Clojure on the server) layers of the login form example from the previous tutorial.
Respect the Don't Repeat Yourself (DRY) principle by sharing validators between the client-side CLJS and the server-side Clojure.
Set the stage for unit testing by learning about the
template sytem and starting the shopping calculator example. Use code
refactoring to satisfy the DRY principle and to solve a cyclic namespaces
Add validators to the
shoppingForm, and do some unit testing.
Make our unit tests portable between Clojure and CLJS by using the
clojurescript.test lib and the
cljx lein plugin.
Integrate the form validators from the server-side Shopping Calculator into the Web UI, so the user is notified with the right error messages when typing invalid values into the form.
A digression to cover two topics on CLJS developer productivity: setting up
a more comfortable browser REPL based on nREPL, and a more
comfortable project structure using the
profiles features of
Learn how to contribute something we need to someone else's library, and how to publish snapshot releases on clojars to use the enhancement in our own project.
Look at the Enfocus library with the objective of sharing as much code as possible with Enlive. Start an open source collaboration by proposing a few improvements to the Enfocus directory structure and the adoption of the clojurescript.test library for implementing unit tests.
Package Enfocus into a
jar, instrument it
with the Piggieback library, publish it on clojars, and use it
as a dependency in a very simple project to see that the changes we made don't
affect the Enfocus codebase, which still works as expected.
Improve Enfocus by applying separation of concerns and implementing a few unit tests. In the process, discover some bugs and correct them by first interacting with Enfocus in the REPL.
Copyright © Mimmo Cosenza, 2012-2015. Released under the Eclipse Public License, the same license as Clojure.