Permalink
Browse files

Minor changes and clean-up.

  • Loading branch information...
1 parent 4644aeb commit 7227b48c66cc422be9ce9b141f25a4db442dee31 @budu committed Mar 31, 2012
Showing with 15 additions and 10 deletions.
  1. +6 −0 readme.md
  2. +1 −1 src/clj/board/core.clj
  3. +8 −9 src/cljs/board/core.cljs
View
@@ -3,6 +3,12 @@
This is a naive implementation of an online whiteboard in under a
hundred lines of Clojure and ClojureScript code.
+## Usage
+
+```
+lein run
+```
+
## License
Copyright (C) 2012 Nicolas Buduroi
View
@@ -1,5 +1,5 @@
(ns board.core
- (:use (lamina [core :exclude [restart]])
+ (:use lamina.core
aleph.http
(ring.middleware resource file-info)
(hiccup core page)))
View
@@ -3,12 +3,11 @@
(def socket (new js/window.WebSocket "ws://localhost:8080"))
+(set! (.-onmessage socket) #(-> % msg->coord draw-circ))
+
(defn $ [selector]
(.querySelector js/document (name selector)))
-(defn listen [element event callback]
- (events/listen element (name event) callback))
-
(def board ($ :#board))
(defn circ [ctx x y d]
@@ -18,6 +17,9 @@
.closePath
.fill))
+(defn draw-circ [[x y]]
+ (-> board (.getContext "2d") (circ x y 5)))
+
(def buttons
{goog.events.BrowserEvent.MouseButton/LEFT :left
goog.events.BrowserEvent.MouseButton/MIDDLE :middle
@@ -28,9 +30,6 @@
(defn pressed? [button]
(@pressed-buttons button))
-(defn draw-circ [[x y]]
- (-> board (.getContext "2d") (circ x y 5)))
-
(defn mouse-move-callback [event]
(let [x (.-clientX event)
y (.-clientY event)]
@@ -39,14 +38,14 @@
(draw-circ [x y]))))
(defn button-event-callback [f event]
- (->> (.-button event) buttons
- (swap! pressed-buttons f)))
+ (->> event .-button buttons (swap! pressed-buttons f)))
(defn msg->coord [message]
(let [[x y] (.split (.-data message) ",")]
[(js/parseInt x) (js/parseInt y)]))
-(set! (.-onmessage socket) #(-> % msg->coord draw-circ))
+(defn listen [element event callback]
+ (events/listen element (name event) callback))
(listen board (name :mousemove) mouse-move-callback)

0 comments on commit 7227b48

Please sign in to comment.