Advertisement
Guest User

Untitled

a guest
Oct 27th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns modern-cljs.procman
  2.   (:require [cljs.core.async :as async
  3.                              :refer [<! >! >!! <!! timeout chan take! put!]]
  4.             [domina :as dom])
  5.   (:require-macros
  6.     [cljs.core.async.macros :refer [go]]))
  7.  
  8.  
  9. (def c (chan))
  10.  
  11. (defn render [q]
  12.   (apply str
  13.     (for [p (reverse q)]
  14.       (str "<div class='proc-" p "'>Process " p "</div>"))))
  15.  
  16.  
  17. (defn peekn
  18.   "Returns vector of (up to) n items from the end of vector v"
  19.   [v n]
  20.   (if (> (count v) n)
  21.     (subvec v (- (count v) n))
  22.     v))
  23.  
  24.  
  25. (defn ^:export init []
  26.   (when (and js/document
  27.            (.-getElementById js/document)))
  28.  
  29.   (go (while true (<! (timeout 250)) (>! c 1)))
  30.   (go (while true (<! (timeout 1000)) (>! c 2)))
  31.   (go (while true (<! (timeout 1500)) (>! c 3)))
  32.   (let [el (dom/by-id "other")
  33.         out (dom/by-id "greeting")]
  34.         (go (loop [q []]
  35.             (dom/set-html! out (render q))
  36.             (recur (-> (conj q (<! c)) (peekn 10)))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement