项目作者: district0x

项目描述 :
district UI module for providing current time
高级语言: Clojure
项目地址: git://github.com/district0x/district-ui-now.git
创建时间: 2017-12-28T21:26:25Z
项目社区:https://github.com/district0x/district-ui-now

开源协议:Eclipse Public License 1.0

下载


district-ui-now

Build Status

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.

Installation

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

API Overview

Warning: district0x modules are still in early stages, therefore API can change in a future.

district.ui.now

This namespace contains now mount module.
This module has no configuration parameters.

  1. (ns my-district.core
  2. (:require [mount.core :as mount]
  3. [district.ui.now]))
  4. (-> (mount/with-args
  5. {})
  6. (mount/start))

district.ui.now.subs

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.

  1. (ns my-district.core
  2. (:require [mount.core :as mount]
  3. [district.ui.now.subs :as now-subs]
  4. [cljs-time.core :as t]))
  5. (defn home-page []
  6. (let [time-remaining (subscribe [::now-subs/time-remaining (t/plus (t/now) (t/seconds 50))])]
  7. (fn []
  8. [:div "Seconds remaining: " (:seconds @time-remaining)])))

district.ui.now.events

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.

  1. (ns my-district.core
  2. (:require [district.ui.now.events :as now-events]
  3. [cljs-time.core :as t]
  4. [re-frame.core :as re-frame]))
  5. (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.

  1. (ns my-district.core
  2. (:require [district.ui.now.events :as now-events]
  3. [re-frame.core :as re-frame]))
  4. (re-frame/dispatch [::now-events/increment-now 8.64e+7])

district.ui.now.queries

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.

Development

  1. lein deps
  2. # To run tests and rerun on changes
  3. lein doo chrome tests