Skip to content

Instantly share code, notes, and snippets.

@dustingetz
Created October 1, 2014 00:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustingetz/1490f9ecd2903203cd99 to your computer and use it in GitHub Desktop.
Save dustingetz/1490f9ecd2903203cd99 to your computer and use it in GitHub Desktop.
proper separation of concerns
(ns quiescent-json-editor.core
(:require [cljs.core.async :as a]
[quiescent :as q :include-macros true]
[quiescent.dom :as d])
(:require-macros [cljs.core.async.macros :as am]))
(q/defcomponent App [state dispatcher]
(d/div {}
(d/pre {} (.stringify js/JSON state))
(d/button {:onClick #(am/go (a/>! dispatcher :inc))})))
(let [render-pending? (atom false)
dispatcher (a/chan)
state (atom 0)]
(defn request-render []
(when (compare-and-set! render-pending? false true)
(.requestAnimationFrame js/window
(fn []
(q/render (App @state dispatcher)
(.getElementById js/document "root"))
(reset! render-pending? false)))))
(defn ^:export main []
(enable-console-print!)
(println "Hello world!")
(request-render)
(am/go
(while true
(let [command (a/<! dispatcher)]
(if (= command :inc)
(do
(println (str "got command " command))
(swap! state inc)))
(request-render))))
)
)
(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment