Created
February 18, 2014 07:44
-
-
Save Jared314/9066327 to your computer and use it in GitHub Desktop.
Om with core.async
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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] | |
(reify | |
om/IInitState | |
(init-state [_] {:value 0 :class ""}) | |
om/IRenderState | |
(render-state [_ state] | |
(dom/td #js {:className (:class state)} (:value state))) | |
om/IWillMount | |
(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] | |
(om/component | |
(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)))))) | |
c)) | |
(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"))}) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defproject processtest "0.1.0-SNAPSHOT" | |
:description "FIXME: write description" | |
:url "http://example.com/FIXME" | |
:license {:name "Eclipse Public License" | |
:url "http://www.eclipse.org/legal/epl-v10.html"} | |
:dependencies [[org.clojure/clojure "1.5.1"] | |
[org.clojure/core.async "0.1.267.0-0d7780-alpha"] | |
[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/main.js.map" | |
; :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