2013-12-16 23:19:36 +01:00
|
|
|
(ns simpleexample
|
2014-01-17 11:12:11 +01:00
|
|
|
(:require [reagent.core :as reagent :refer [atom]]))
|
2013-12-16 23:19:36 +01:00
|
|
|
|
2015-02-09 09:43:43 +01:00
|
|
|
(defonce timer (atom (js/Date.)))
|
2013-12-16 23:19:36 +01:00
|
|
|
|
2015-02-09 09:43:43 +01:00
|
|
|
(defonce time-color (atom "#f34"))
|
|
|
|
|
|
|
|
(defonce time-updater (js/setInterval
|
|
|
|
#(reset! timer (js/Date.)) 1000))
|
2013-12-16 23:19:36 +01:00
|
|
|
|
2014-02-15 13:50:10 +01:00
|
|
|
(defn greeting [message]
|
|
|
|
[:h1 message])
|
2013-12-16 23:19:36 +01:00
|
|
|
|
|
|
|
(defn clock []
|
2014-01-07 12:45:08 +01:00
|
|
|
(let [time-str (-> @timer .toTimeString (clojure.string/split " ") first)]
|
2013-12-16 23:19:36 +01: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 13:50:10 +01:00
|
|
|
[greeting "Hello world, it is now"]
|
2013-12-16 23:19:36 +01:00
|
|
|
[clock]
|
|
|
|
[color-input]])
|
|
|
|
|
|
|
|
(defn ^:export run []
|
2015-02-09 12:07:46 +01:00
|
|
|
(reagent/render [simple-example]
|
|
|
|
(js/document.getElementById "app")))
|