2013-12-16 22:19:36 +00:00
|
|
|
|
|
|
|
(ns simpleexample
|
2014-01-17 10:12:11 +00:00
|
|
|
(:require [reagent.core :as reagent :refer [atom]]))
|
2013-12-16 22:19:36 +00:00
|
|
|
|
|
|
|
(def timer (atom (js/Date.)))
|
|
|
|
(def time-color (atom "#f34"))
|
|
|
|
|
|
|
|
(defn update-time [time]
|
2014-01-06 21:27:22 +00:00
|
|
|
;; Update the time every 1/10 second to be accurate...
|
2013-12-16 22:19:36 +00:00
|
|
|
(js/setTimeout #(reset! time (js/Date.)) 100))
|
|
|
|
|
2014-02-15 12:50:10 +00:00
|
|
|
(defn greeting [message]
|
|
|
|
[:h1 message])
|
2013-12-16 22:19:36 +00:00
|
|
|
|
|
|
|
(defn clock []
|
|
|
|
(update-time timer)
|
2014-01-07 11:45:08 +00:00
|
|
|
(let [time-str (-> @timer .toTimeString (clojure.string/split " ") first)]
|
2013-12-16 22:19:36 +00:00
|
|
|
[:div.example-clock
|
|
|
|
{:style {:color @time-color}}
|
|
|
|
time-str]))
|
|
|
|
|
|
|
|
(defn color-input []
|
|
|
|
[:div.color-input
|
|
|
|
"Time color: "
|
|
|
|
[:input {:type "text"
|
|
|
|
:value @time-color
|
|
|
|
:on-change #(reset! time-color (-> % .-target .-value))}]])
|
|
|
|
|
|
|
|
(defn simple-example []
|
|
|
|
[:div
|
2014-02-15 12:50:10 +00:00
|
|
|
[greeting "Hello world, it is now"]
|
2013-12-16 22:19:36 +00:00
|
|
|
[clock]
|
|
|
|
[color-input]])
|
|
|
|
|
|
|
|
(defn ^:export run []
|
2014-01-17 10:12:11 +00:00
|
|
|
(reagent/render-component [simple-example]
|
|
|
|
(.-body js/document)))
|