re-frame/src/re_frame/core.cljs

87 lines
2.6 KiB
Plaintext
Raw Normal View History

2015-02-25 11:03:02 +00:00
(ns re-frame.core
(:require
2015-02-25 11:03:25 +00:00
[re-frame.handlers :as handlers]
[re-frame.subs :as subs]
[re-frame.router :as router]
2015-05-02 00:46:05 +00:00
[re-frame.utils :as utils]
2016-06-14 11:09:21 +00:00
[re-frame.undo :as undo]
2015-03-01 20:58:34 +00:00
[re-frame.middleware :as middleware]))
2015-02-25 11:03:02 +00:00
;; -- API -------
;; See also macros in clj file
2015-02-25 11:03:02 +00:00
(def dispatch router/dispatch)
(def dispatch-sync router/dispatch-sync)
2015-02-25 11:03:02 +00:00
(def register-sub subs/register)
(def register-pure-sub subs/register-pure)
(def clear-sub-handlers! subs/clear-handlers!)
(def subscribe subs/subscribe)
2015-02-25 11:03:02 +00:00
(def clear-event-handlers! handlers/clear-handlers!)
2015-02-25 11:03:02 +00:00
(def pure middleware/pure)
2015-03-01 20:58:34 +00:00
(def debug middleware/debug)
2015-02-25 11:03:02 +00:00
(def path middleware/path)
2015-03-05 00:32:36 +00:00
(def enrich middleware/enrich)
(def trim-v middleware/trim-v)
(def after middleware/after)
(def on-changes middleware/on-changes)
2016-06-14 11:09:21 +00:00
;; -- Undo API -----
2016-06-23 13:41:20 +00:00
;; For an explanation of the undo/redo capabilities:
2016-06-14 11:09:21 +00:00
;; https://github.com/Day8/re-frame/wiki/Undo-&-Redo
(def undoable undo/undoable)
2016-06-23 13:41:20 +00:00
(def undo-config! undo/undo-config!)
2016-06-14 11:09:21 +00:00
2015-04-26 21:38:37 +00:00
;; -- Logging -----
2015-05-02 00:46:05 +00:00
;; re-frame uses the logging functions: warn, log, error, group and groupEnd
;; By default, these functions map directly to the js/console implementations,
;; but you can override with your own (set or subset).
2016-06-03 02:58:06 +00:00
;; Example Usage:
;; (defn my-warn-fn [& args] (post-it-somewhere (apply str args)))
2016-06-03 02:58:06 +00:00
;; (re-frame.core/set-loggers! {:warn my-warn-fn})
2015-04-26 21:38:37 +00:00
(def set-loggers! utils/set-loggers!)
2015-02-25 11:03:02 +00:00
2015-05-02 00:46:05 +00:00
2015-03-02 14:03:09 +00:00
;; -- Convenience API -------
2015-02-25 11:03:02 +00:00
2015-03-05 00:32:36 +00:00
;; Almost 100% of handlers will be pure, so make it easy to
2015-04-17 12:51:03 +00:00
;; register with "pure" middleware in the correct (left-hand-side) position.
2015-03-04 23:40:02 +00:00
(defn register-handler
2015-02-25 11:03:02 +00:00
([id handler]
2015-03-04 23:40:02 +00:00
(handlers/register-base id pure handler))
2015-02-25 11:03:02 +00:00
([id middleware handler]
2015-03-04 23:40:02 +00:00
(handlers/register-base id [pure middleware] handler)))
;; -- Event Procssing Callbacks
(defn add-post-event-callback
"Registers a callback function 'f'.
2015-12-08 20:40:47 +00:00
f will be called after each dispatched event is procecessed
f will be called with two arguments:
- the event's vector. That which was dispatched orignally.
2015-12-08 20:40:47 +00:00
- the further event queue - what is still to be processed. A PersistentQueue.
This is useful in advanced cases like:
- you are implementing a complex bootstrap pipeline
- you want to create your own handling infrastructure, with perhaps multiple
handlers for the one event, etc. Hook in here.
- libraries providing 'isomorphic javascript' rendering on Nodejs or Nashorn.
"
[f]
(router/add-post-event-callback re-frame.router/event-queue f))
(defn remove-post-event-callback
[f]
(router/remove-post-event-callback re-frame.router/event-queue f))