Move reagent-id fn to re-frame.interop

This commit is contained in:
Daniel Compton 2016-12-15 13:25:53 +13:00
parent 5364a83aee
commit b53062e859
4 changed files with 21 additions and 17 deletions

View File

@ -76,3 +76,8 @@
;; currentTimeMillis may count backwards in some scenarios, but as this is used for tracing
;; it is preferable to the slower but more accurate System.nanoTime.
(System/currentTimeMillis))
(defn reagent-id
"Doesn't make sense in a Clojure context currently."
[reactive-val]
nil)

View File

@ -41,3 +41,16 @@
(if (exists? js/performance.now)
(js/performance.now)
(js/Date.now)))
(defn reagent-id
"Produces an id for reactive Reagent values
e.g. reactions, ratoms, cursors."
[reactive-val]
(when (implements? reagent.ratom/IReactiveAtom reactive-val)
(str (condp instance? reactive-val
reagent.ratom/RAtom "ra"
reagent.ratom/RCursor "rc"
reagent.ratom/Reaction "rx"
reagent.ratom/Track "tr"
"other")
(hash reactive-val))))

View File

@ -1,9 +1,9 @@
(ns re-frame.subs
(:require
[re-frame.db :refer [app-db]]
[re-frame.interop :refer [add-on-dispose! debug-enabled? make-reaction ratom? deref? dispose!]]
[re-frame.interop :refer [add-on-dispose! debug-enabled? make-reaction ratom? deref? dispose! reagent-id]]
[re-frame.loggers :refer [console]]
[re-frame.utils :refer [first-in-vector reagent-id]]
[re-frame.utils :refer [first-in-vector]]
[re-frame.registrar :refer [get-handler clear-handlers register-handler]]
[re-frame.trace :as trace :include-macros true]))

View File

@ -1,7 +1,6 @@
(ns re-frame.utils
(:require
[re-frame.loggers :refer [console]]
#?(:cljs [reagent.ratom :as ratom])))
[re-frame.loggers :refer [console]]))
(defn dissoc-in
"Dissociates an entry from a nested associative structure returning a new
@ -23,16 +22,3 @@
(if (vector? v)
(first v)
(console :error "re-frame: expected a vector, but got:" v)))
(defn reagent-id
"Produces an id for reactive Reagent values
e.g. reactions, ratoms, cursors."
[reactive-val]
#?(:cljs (when (implements? ratom/IReactiveAtom reactive-val)
(str (condp instance? reactive-val
ratom/RAtom "ra"
ratom/RCursor "rc"
ratom/Reaction "rx"
ratom/Track "tr"
"other")
(hash reactive-val)))))