项目作者: district0x

项目描述 :
district UI module for displaying notifications (core logic) .
高级语言: Clojure
项目地址: git://github.com/district0x/district-ui-notification.git
创建时间: 2018-02-07T17:29:13Z
项目社区:https://github.com/district0x/district-ui-notification

开源协议:Eclipse Public License 1.0

下载


district-ui-notification

Build Status

Clojurescript re-mount module, that provides core logic for transaction notifications. This module does not provide reagent UI component for notifications, only
logic to build the component upon. This way many different reagent components can be build on top of this module.

Installation

Add [district0x/district-ui-notification "1.0.1"] into your project.clj.

Include [district.ui.notification] in your CLJS file, where you use mount/start.

Usage

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

district.ui.notification" class="reference-link"> district.ui.notification

This namespace contains district-ui-notification mount module.

You can pass following args to initiate this module:

  • :default-show-duration Specifies the default amount of time (in milliseconds) the notification will be displayed for. Default: 5000
  • :default-hide-duration Specifies the amount of time (in milliseconds) between consecutive notifications. Default: 2000
  1. (ns my-district
  2. (:require [mount.core :as mount]
  3. [district.ui.notification]))
  4. (-> (mount/with-args {:notification {:default-show-duration 2000
  5. :default-hide-duration 1000}})
  6. (mount/start))

The validity of the args passed to the module will be checked at runtime if you have set the clojure.spec.check-asserts system property to true:

  1. (ns my-district
  2. (:require [cljs.spec.alpha :as s]))
  3. (s/check-asserts true)

If the arguments do not conform to the ::opts spec, an exception is thrown.

district.ui.notification.events" class="reference-link"> district.ui.notification.events

re-frame events provided by this module:

::show" class="reference-link"> ::show

This is typically the only event you should ever need. Queues the next notification to be displayed.
You can pass the following arguments:

  • :message to be displayed
  • :show-duration (which overrides the default default-show-duration)
  • an arbitrary number of other arguments
  1. (ns my-district
  2. (:require [re-frame.core :as re-frame]
  3. [district.ui.notification.events :as events]))
  4. (re-frame/dispatch [::events/show
  5. {:show-duration 3000
  6. :message "FOO"
  7. :foo "bar"}])

If no :show-duration argument is provided in the arguments map, the :default-show-duration is assumed:

  1. (re-frame/dispatch [::events/show {:message "FOO"}])

You can also dispatch this event with a string as the only argument:

  1. (re-frame/dispatch [::events/show "FOO"])

which is just a synctatic sugar for the former.

::show-notification" class="reference-link"> ::show-notification

Sets active (current) notification to be displayed, bypassing the queue.

::hide-notification" class="reference-link"> ::hide-notification

Sets :open of the active notification to false.

district.ui.notification.subs" class="reference-link"> district.ui.notification.subs

re-frame subscriptions provided by this module:

::notification" class="reference-link"> ::notification

This is typically the only subscription you will need. Returns active notification.
Subscription returns a map with key-value pairs:

  1. (ns my-district
  2. (:require [district.ui.notification.subs :as subs]
  3. [re-frame.core :as re-frame]))
  4. (let [{:keys [:open? :message :foo]} @(re-frame/subscribe [::subs/notification])]
  5. (prn message))

district.ui.notification.queries" class="reference-link"> district.ui.notification.queries

DB queries provided by this module:
You should use them in your events or subscriptions.

queue-notification" class="reference-link"> queue-notification

Adds a notification to the end of queue.

pop-notification" class="reference-link"> pop-notification

Removes the first notification in queue.

peek-notification" class="reference-link"> peek-notification

Return the first notification in queue, does not alter the queue.

show-notification" class="reference-link"> show-notification

Sets the current notification to be displayed. Used by the ::show-notification event.

hide-notification" class="reference-link"> hide-notification

Sets :open? key of the current notification to false. Used by the ::hide-notification event.

notification" class="reference-link"> notification

Returns the current notification. Used by the ::notification sub.

district.ui.notification.spec" class="reference-link"> district.ui.notification.spec

specs provided by this module:

::notification" class="reference-link">::notification

This is typically the only spec you will need. Defines the valid argument for the ::show event.

  1. (ns my-district
  2. (:require [cljs.spec.alpha :as s]
  3. [district.ui.notification.spec :as spec]))
  4. (s/valid? ::spec/notification {:show-duration 3000
  5. :message "FOO"
  6. :foo "bar"})

::opts" class="reference-link">::opts

Spec for the options passed to the module. You can toggle whether this spec is checked, see district.ui.notification.

Development

Run test suite:

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

Install into local repo:

  1. lein cljsbuild test
  2. lein install