Merge pull request #76 from grammati/ipending
Do not start a DerefableState as a side-effect of printing
This commit is contained in:
commit
891869721c
3 changed files with 29 additions and 4 deletions
|
|
@ -104,6 +104,9 @@
|
||||||
(swap! running dissoc state)
|
(swap! running dissoc state)
|
||||||
(update-meta! [state :status] #{:stopped})))
|
(update-meta! [state :status] #{:stopped})))
|
||||||
|
|
||||||
|
(defn running-states []
|
||||||
|
(set (keys @running)))
|
||||||
|
|
||||||
(deftype DerefableState [name]
|
(deftype DerefableState [name]
|
||||||
#?(:clj clojure.lang.IDeref
|
#?(:clj clojure.lang.IDeref
|
||||||
:cljs IDeref)
|
:cljs IDeref)
|
||||||
|
|
@ -113,7 +116,13 @@
|
||||||
(let [{:keys [status inst] :as state} (@meta-state name)]
|
(let [{:keys [status inst] :as state} (@meta-state name)]
|
||||||
(when-not (:started status)
|
(when-not (:started status)
|
||||||
(up name state (atom #{})))
|
(up name state (atom #{})))
|
||||||
@inst)))
|
@inst))
|
||||||
|
#?(:clj clojure.lang.IPending
|
||||||
|
:cljs IPending)
|
||||||
|
(#?(:clj isRealized
|
||||||
|
:cljs -realized?)
|
||||||
|
[_]
|
||||||
|
(boolean ((running-states) name))))
|
||||||
|
|
||||||
(defn on-reload-meta [s-var]
|
(defn on-reload-meta [s-var]
|
||||||
(or (-> s-var meta :on-reload)
|
(or (-> s-var meta :on-reload)
|
||||||
|
|
@ -181,9 +190,6 @@
|
||||||
(with-ns ns name))
|
(with-ns ns name))
|
||||||
v)))
|
v)))
|
||||||
|
|
||||||
(defn running-states []
|
|
||||||
(set (keys @running)))
|
|
||||||
|
|
||||||
(defn- unvar-state [s]
|
(defn- unvar-state [s]
|
||||||
(->> s (drop 2) (apply str))) ;; magic 2 is removing "#'" in state name
|
(->> s (drop 2) (apply str))) ;; magic 2 is removing "#'" in state name
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
mount.test.start-without
|
mount.test.start-without
|
||||||
mount.test.start-with
|
mount.test.start-with
|
||||||
mount.test.start-with-states
|
mount.test.start-with-states
|
||||||
|
mount.test.printing
|
||||||
))
|
))
|
||||||
|
|
||||||
#?(:clj (alter-meta! *ns* assoc ::load false))
|
#?(:clj (alter-meta! *ns* assoc ::load false))
|
||||||
|
|
@ -31,6 +32,7 @@
|
||||||
'mount.test.start-without
|
'mount.test.start-without
|
||||||
'mount.test.start-with
|
'mount.test.start-with
|
||||||
'mount.test.start-with-states
|
'mount.test.start-with-states
|
||||||
|
'mount.test.printing
|
||||||
))
|
))
|
||||||
|
|
||||||
(defn run-tests []
|
(defn run-tests []
|
||||||
|
|
|
||||||
17
test/core/mount/test/printing.cljc
Normal file
17
test/core/mount/test/printing.cljc
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
(ns mount.test.printing
|
||||||
|
(:require
|
||||||
|
#?@(:cljs [[cljs.test :as t :refer-macros [is are deftest testing use-fixtures]]
|
||||||
|
[mount.core :as mount :refer-macros [defstate]]]
|
||||||
|
:clj [[clojure.test :as t :refer [is are deftest testing use-fixtures]]
|
||||||
|
[mount.core :as mount :refer [defstate]]])))
|
||||||
|
|
||||||
|
#?(:clj (alter-meta! *ns* assoc ::load false))
|
||||||
|
|
||||||
|
(defstate foo
|
||||||
|
:start (do (println "Starting!") 42))
|
||||||
|
|
||||||
|
(deftest test-printing-has-no-side-effects
|
||||||
|
;; Test that printing an unstarted DerefableState does not have the
|
||||||
|
;; side-effect of starting it
|
||||||
|
(println foo)
|
||||||
|
(is (not= 42 foo)))
|
||||||
Loading…
Reference in a new issue