Skip to content

Instantly share code, notes, and snippets.

Created Feb 18, 2014
What would you like to do?
Om with core.async
(ns processtest.core
(:require [cljs.core.async :as async
:refer [<! >! chan put! timeout]]
[om.core :as om :include-macros true]
[om.dom :as dom :include-macros true])
(:require-macros [cljs.core.async.macros :refer [go]]))
(defn cell1 [data owner]
(init-state [_] {:value 0 :class ""})
(render-state [_ state]
(dom/td #js {:className (:class state)} (:value state)))
(will-mount [_]
(let [c (:update-channel data)]
(go (while true
(let [[v g] (<! c)]
(om/set-state! owner :value v)
(om/set-state! owner :class g))
(<! (timeout (rand-int 100)))))))))
(defn table1 [data owner]
(apply dom/table nil
(for [x (range (:height data))]
(apply dom/tr nil (om/build-all cell1 (repeat (:width data) data)))))))
(defn build-producer [m]
(let [c (chan)]
(go (loop [i 0]
(let [g (str "group" (mod i 5))]
(dotimes [n (inc (rand-int m))]
(>! c [(rand-int 10) g]))
(when (< i 1000)
(recur (inc i))))))
(def width 20)
(def height 20)
(om/root table1 {:update-channel (build-producer (* height width))
:height height
:width width}
{:target (. js/document (getElementById "big-table"))})
(defproject processtest "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url ""
:license {:name "Eclipse Public License"
:url ""}
:dependencies [[org.clojure/clojure "1.5.1"]
[org.clojure/core.async ""]
[org.clojure/clojurescript "0.0-2156"]
[om "0.4.1"]]
:plugins [[lein-cljsbuild "1.0.2"]]
:cljsbuild {:builds [{:source-paths ["src-cljs"]
:compiler {:output-dir "resources/public/js"
:output-to "resources/public/js/main.js"
:optimizations :none
:pretty-print false
:source-map "resources/public/js/"
; :preamble ["react/react.min.js"]
; :externs ["react/externs/react.js"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment