district UI module for providing current time
Clojurescript re-mount module, that provides current time.
Useful when you need to display time remaining counter on the website (e.g for auctions). This module uses cljs-time.
Add [district0x/district-ui-now "1.0.2"]
into your project.clj
Include [district.ui.now]
in your CLJS file, where you use mount/start
Warning: district0x modules are still in early stages, therefore API can change in a future.
This namespace contains now mount module.
This module has no configuration parameters.
(ns my-district.core
(:require [mount.core :as mount]
[district.ui.now]))
(-> (mount/with-args
{})
(mount/start))
re-frame subscriptions provided by this module:
::now []
" class="reference-link">::now []
Returns cljs-time time of now.
::time-remaining [to-time]
" class="reference-link">::time-remaining [to-time]
Returns time remaining from now to to-time
.
(ns my-district.core
(:require [mount.core :as mount]
[district.ui.now.subs :as now-subs]
[cljs-time.core :as t]))
(defn home-page []
(let [time-remaining (subscribe [::now-subs/time-remaining (t/plus (t/now) (t/seconds 50))])]
(fn []
[:div "Seconds remaining: " (:seconds @time-remaining)])))
re-frame events provided by this module:
::update-now
" class="reference-link">::update-now
Event fired every second to update now in re-frame db.
::set-now
" class="reference-link">::set-now
Event to set now time in re-frame db, from which time incrementing continues.
(ns my-district.core
(:require [district.ui.now.events :as now-events]
[cljs-time.core :as t]
[re-frame.core :as re-frame]))
(re-frame/dispatch [::now-events/set-now (t/minus (t/now) (t/years 1))])
::increment-now
" class="reference-link">::increment-now
Event to increment now time in re-frame db by a number of milliseconds.
(ns my-district.core
(:require [district.ui.now.events :as now-events]
[re-frame.core :as re-frame]))
(re-frame/dispatch [::now-events/increment-now 8.64e+7])
DB queries provided by this module:
You should use them in your events, instead of trying to get this module’s
data directly with get-in
into re-frame db.
now [db]
" class="reference-link">now [db]
Works the same way as sub ::now
.
time-remaining [db to-time]
" class="reference-link">time-remaining [db to-time]
Works the same way as sub ::time-remaining
.
assoc-now [db now]
" class="reference-link">assoc-now [db now]
Associates new now and returns new re-frame db.
lein deps
# To run tests and rerun on changes
lein doo chrome tests