Skip to content

Instantly share code, notes, and snippets.

@tgvashworth
Created April 15, 2014 23:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tgvashworth/10789694 to your computer and use it in GitHub Desktop.
Save tgvashworth/10789694 to your computer and use it in GitHub Desktop.
om and core-async
(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