Created
April 15, 2014 23:43
-
-
Save tgvashworth/10789694 to your computer and use it in GitHub Desktop.
om and core-async
This file contains 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 om-do.core | |
(:require-macros [cljs.core.async.macros :refer [go]]) | |
(:require [om.core :as om :include-macros true] | |
[om.dom :as dom :include-macros true] | |
[cljs.core.async :refer [put! <! >! chan timeout alts!]])) | |
(enable-console-print!) | |
(def app-state | |
(atom {})) | |
(defn pinger-view [app-state-cursor owner] | |
(reify | |
om/IInitState | |
(init-state [_] | |
{:the-chan (chan)}) | |
om/IWillMount | |
(will-mount [_] | |
(let [{:keys [the-chan]} (om/get-state owner)] | |
(go | |
(loop [] | |
(let [chan-data (<! the-chan)] | |
(println "pong" chan-data)))) | |
(go | |
(loop [c (timeout 1000)] | |
(let [_ (<! c)] | |
(println "ping") | |
(put! the-chan {:some 0 :data 1}) | |
(recur (timeout 1000))))))) | |
om/IRender | |
(render [_] | |
(println "rendering pinger-view") | |
(dom/div #js {} "test")))) | |
(om/root pinger-view app-state | |
{:target (. js/document (getElementById "app"))}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment