Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added README.md and Demo.md

  • Loading branch information...
commit 8dd2f97ffc8eb17fe3af38331114cf461451f83c 1 parent 06d44dc
@danskarda danskarda authored
Showing with 73 additions and 18 deletions.
  1. +58 −0 Demo.md
  2. +15 −18 README.md
View
58 Demo.md
@@ -0,0 +1,58 @@
+# Adding ClojureScript to Chat Room Demo
+
+In the last iteration of our demo we add ClojureScript to improve our
+(simple chat server)[demo/demo-3-chat]. We will poll server using XhrIo
+request to fetch new chat room messages without page refresh.
+
+lein-cljsbuild
+--------------
+
+We use [lein-cljsbuild](https://github.com/emezeske/lein-cljsbuild) Leiningen
+plugin to integrate ClojureScript to our project. See [project.clj](project.clj)
+for changes and cljsbuild configuration.
+
+Type `lein cljsbuild once` to compile .cljs files to JavaScript.
+
+To modify our ClojureScript life in the browser, we can also start ClojureScript
+REPL using `lein cljsbuild repl-listen`. This command will listen for repl
+request on port 9000. Then we need to connect the browser.
+
+Once we compile ClojureScript files, we can launch Jetty web server, point
+our browser to main page and enter a chat room. Then we launch JavaScript developer
+console in Chrome and type `demo.repl.start_repl ()`.
+
+Crossovers
+----------
+
+Crossovers in Cljsbuild enable code sharing between Clojure and
+ClojureScript. ClojureScript files are stored in [src-cljs/](src-cljs)
+directory, crossovers are in stored in [src/](src) directory and
+configured in [project.clj](project.clj) file.
+
+We will use crossover functionality to share message rendering in
+[message.clj](src/demo/message.clj). Output from function `render-message`
+can be rendered into HTML by both Hiccup library and `clojure.browser.dom`.
+
+Extending server
+----------------
+
+To enable ClojureScript polling we performed two changes to [core.clj](src/demo/core.clj):
+
+* `(resources "/")` to serve compiled JavaScript files from resources/ directory.
+* we added api-routing to fulfill browser polling requests.
+
+
+In [page.clj](src/demo/page.clj) we included JavaScript and added new attributes
+to identify messages from JavaScript.
+
+Server polling from browser
+---------------------------
+
+ClojureScript uses [Google Closure](http://closure-library.googlecode.com/svn/docs/index.html) library.
+We use `goog.net.XhrIo` and `goog.Timer` to build simple polling mechanism.
+
+`clojure.browser.dom`, `net` and `event` libraries are simple ClojureScript wrappers around
+Google Closure functionality.
+
+
+
View
33 README.md
@@ -1,25 +1,22 @@
-# demo
+# Clojure & Web - simple Demo
-project.clj
------------
+The code in this repo was part of 'Clojure & Web' talk prepared by
+[Daniel Skarda](https://github.com/orfelyus). See [Google Presentation](goo.gl/nEFWB) for slides.
-For the second demo we included two libraries: hiccup and
-compojure.
+The talk was presented on [Prague Lambda Meetup](http://www.meetup.com/Lambda-Meetup-Group/)
+on September 26th 2012.
+
+The goal of the talk was to give an overview of Clojure libraries for
+
+* simple request handling (see (Demo 1)[demo/demo-1-jetty])
+* HTML generation using [Hiccup](https://github.com/weavejester/hiccup)
+* request routing using [Compojure](https://github.com/weavejester/compojure) (see (Demo 2)[demo-2-compojure] and (Demo 3)[demo-3-chat]).
+* using ClojureScript for browser specific tasks
+* deploying on Heroku
+
+See demos in [demo/](demo/) directory and [Demo.md](Demo.md) for description of last demo.
- https://github.com/weavejester/hiccup
- https://github.com/weavejester/compojure
-
-For easier request handling we also added ring-core and
-ring-devel. Both include definition of ring "middleware".
-Hiccup
-------
-Hiccup is a library for HTML rendering from Clojure data
-structures
-Compojure
----------
-Is a DSL (Domain Specific Language) for writing routing
-information for Ring.
Please sign in to comment.
Something went wrong with that request. Please try again.