I would like to write something like a clock app. The state is basically a number which is repeatedly incremented. One way of doing it can be seen here.
(ns chest-example.core
(:require [om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]
[cljs.core.async :as async])
(:require-macros [cljs.core.async.macros :refer [go]]))
(defonce app-state (atom {:time 0}))
(defn clock-view [data owner]
(reify
om/IRender
(render [_]
(dom/div nil (pr-str data)))))
(go (while true
(async/<! (async/timeout 1000))
(om/transact! (om/root-cursor app-state) :time inc)))
(defn main []
(om/root
clock-view
app-state
{ :target (. js/document (getElementById "clock"))}))
The problem I have with this that this is not reloadable code. Once I refresh code through fig wheel the incrementing gets faster since there are several things updating the state.
I tried to experiment with various ideas (basically making different components to own the go statement code) but I was not able to come up with something that would work.
Does anyone have a neat solution for this or do I just have to stick with it during development?