CLJC: address (some of) Daniel's review comments
This commit is contained in:
parent
cc33fe5a95
commit
951682db81
|
@ -1,7 +1,31 @@
|
||||||
(ns re-frame.interop)
|
(ns re-frame.interop
|
||||||
|
(:import java.util.concurrent.Executors))
|
||||||
|
|
||||||
|
|
||||||
|
;; The purpose of this file is to provide JVM-runnable implementations of the
|
||||||
|
;; CLJS equivalents in interop.cljs.
|
||||||
|
;;
|
||||||
|
;; These implementations are to enable you to bring up a re-frame app on the JVM
|
||||||
|
;; in order to run tests, or to develop at a JVM REPL instead of a CLJS one.
|
||||||
|
;;
|
||||||
|
;; Please note, though, that the purpose here *isn't* to fully replicate all of
|
||||||
|
;; re-frame's behaviour in a real CLJS environment. We don't have Reagent or
|
||||||
|
;; React on the JVM, and we don't try to mimic the stateful lifecycles that they
|
||||||
|
;; embody.
|
||||||
|
;;
|
||||||
|
;; In particular, if you're performing side effects in any code that's triggered
|
||||||
|
;; by a change to a Ratom's value, and not via a call to `dispatch`, then you're
|
||||||
|
;; going to have a hard time getting any accurate tests with this code.
|
||||||
|
;; However, if your subscriptions and Reagent render functions are pure, and
|
||||||
|
;; your side-effects are all managed by event handlers, then hopefully this will
|
||||||
|
;; allow you to write some useful tests that can run on the JVM.
|
||||||
|
|
||||||
|
|
||||||
|
(defonce ^:private executor (Executors/newSingleThreadExecutor))
|
||||||
|
|
||||||
(defn next-tick [f]
|
(defn next-tick [f]
|
||||||
(.start (Thread. f)))
|
(.execute executor f)
|
||||||
|
nil)
|
||||||
|
|
||||||
(def empty-queue clojure.lang.PersistentQueue/EMPTY)
|
(def empty-queue clojure.lang.PersistentQueue/EMPTY)
|
||||||
|
|
||||||
|
@ -10,17 +34,14 @@
|
||||||
(def debug-enabled? true)
|
(def debug-enabled? true)
|
||||||
|
|
||||||
(defn ratom [x]
|
(defn ratom [x]
|
||||||
(let [result (atom x)]
|
(atom x))
|
||||||
(alter-meta! result assoc ::ratom? true)
|
|
||||||
result))
|
|
||||||
|
|
||||||
(defn ratom? [maybe-ratom]
|
(defn ratom? [x]
|
||||||
(and (satisfies? clojure.lang.IAtom maybe-ratom)
|
(satisfies? clojure.lang.IAtom x))
|
||||||
(::ratom? (meta maybe-ratom))))
|
|
||||||
|
|
||||||
(defn make-reaction
|
(defn make-reaction
|
||||||
"On JVM Clojure, return an atom-like thing which invokes the given function on
|
"On JVM Clojure, return a `deref`-able thing which invokes the given function
|
||||||
every deref. That is, `make-reaction` here provides precisely none of the
|
on every `deref`. That is, `make-reaction` here provides precisely none of the
|
||||||
benefits of `reagent.ratom/make-reaction` (which only invokes its function if
|
benefits of `reagent.ratom/make-reaction` (which only invokes its function if
|
||||||
the reactions that the function derefs have changed value). But so long as `f`
|
the reactions that the function derefs have changed value). But so long as `f`
|
||||||
only depends on other reactions (which also behave themselves), the only
|
only depends on other reactions (which also behave themselves), the only
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
(defn ratom [x]
|
(defn ratom [x]
|
||||||
(reagent.core/atom x))
|
(reagent.core/atom x))
|
||||||
|
|
||||||
(defn ratom? [maybe-ratom]
|
(defn ratom? [x]
|
||||||
(satisfies? reagent.ratom/IReactiveAtom maybe-ratom))
|
(satisfies? reagent.ratom/IReactiveAtom x))
|
||||||
|
|
||||||
(defn make-reaction [f]
|
(defn make-reaction [f]
|
||||||
(reagent.ratom/make-reaction f))
|
(reagent.ratom/make-reaction f))
|
||||||
|
|
|
@ -227,7 +227,7 @@
|
||||||
stack #?(:cljs (->> (js/Error. (str "Event " (first event-v) " dispatched from here:"))
|
stack #?(:cljs (->> (js/Error. (str "Event " (first event-v) " dispatched from here:"))
|
||||||
.-stack
|
.-stack
|
||||||
clojure.string/split-lines
|
clojure.string/split-lines
|
||||||
(remove #(re-find #"react.inc.js|\(native\)" %))
|
(remove #(re-find #"react\.inc\.js|\(native\)" %))
|
||||||
(clojure.string/join "\n"))
|
(clojure.string/join "\n"))
|
||||||
:clj "n/a")]
|
:clj "n/a")]
|
||||||
(if (nil? event-v)
|
(if (nil? event-v)
|
||||||
|
|
Loading…
Reference in New Issue