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]
|
2015-03-04 13:00:36 +00:00
|
|
|
[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 -------
|
2016-06-11 12:23:53 +00:00
|
|
|
;; See also macros in clj file
|
2015-02-25 11:03:02 +00:00
|
|
|
|
2015-03-04 13:00:36 +00:00
|
|
|
(def dispatch router/dispatch)
|
|
|
|
(def dispatch-sync router/dispatch-sync)
|
2015-02-25 11:03:02 +00:00
|
|
|
|
2015-04-24 23:50:46 +00:00
|
|
|
(def register-sub subs/register)
|
2016-06-14 02:08:57 +00:00
|
|
|
(def register-pure-sub subs/register-pure)
|
2015-04-24 23:50:46 +00:00
|
|
|
(def clear-sub-handlers! subs/clear-handlers!)
|
|
|
|
(def subscribe subs/subscribe)
|
2015-02-25 11:03:02 +00:00
|
|
|
|
|
|
|
|
2015-04-24 23:50:46 +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)
|
2015-02-26 15:07:35 +00:00
|
|
|
(def trim-v middleware/trim-v)
|
2015-03-04 13:00:36 +00:00
|
|
|
(def after middleware/after)
|
2015-04-24 14:06:51 +00:00
|
|
|
(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
|
2016-06-11 12:23:53 +00:00
|
|
|
;; 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:
|
2016-06-11 12:23:53 +00:00
|
|
|
;; (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)))
|
2015-03-02 12:02:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-12-07 21:19:59 +00:00
|
|
|
;; -- Event Procssing Callbacks
|
|
|
|
|
|
|
|
(defn add-post-event-callback
|
2016-06-03 02:49:49 +00:00
|
|
|
"Registers a callback function 'f'.
|
2015-12-08 20:40:47 +00:00
|
|
|
f will be called after each dispatched event is procecessed
|
2016-06-11 12:23:53 +00:00
|
|
|
f will be called with two arguments:
|
2015-12-07 21:19:59 +00:00
|
|
|
- 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.
|
2016-06-03 02:49:49 +00:00
|
|
|
|
|
|
|
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.
|
2016-06-11 12:23:53 +00:00
|
|
|
- libraries providing 'isomorphic javascript' rendering on Nodejs or Nashorn.
|
2015-12-07 21:19:59 +00:00
|
|
|
"
|
|
|
|
[f]
|
|
|
|
(router/add-post-event-callback re-frame.router/event-queue f))
|
|
|
|
|
2016-06-03 02:49:49 +00:00
|
|
|
|
|
|
|
(defn remove-post-event-callback
|
|
|
|
[f]
|
|
|
|
(router/remove-post-event-callback re-frame.router/event-queue f))
|