Created
October 1, 2014 00:47
-
-
Save dustingetz/1490f9ecd2903203cd99 to your computer and use it in GitHub Desktop.
proper separation of concerns
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 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