From 2d050e9055418982c29ff284d84b60aa4ad6ceda Mon Sep 17 00:00:00 2001 From: anatoly Date: Mon, 19 Dec 2022 15:17:21 -0500 Subject: [PATCH] fix: swap-states non string rollback thanks to @egg-juxt for bringing it up --- boot.properties | 2 ++ build.boot | 5 +++-- project.clj | 2 +- src/mount/core.cljc | 4 ++-- test/core/mount/test/composable_fns.cljc | 10 ++++++++++ 5 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 boot.properties diff --git a/boot.properties b/boot.properties new file mode 100644 index 0000000..d2c1a92 --- /dev/null +++ b/boot.properties @@ -0,0 +1,2 @@ +BOOT_VERSION=2.7.1 +BOOT_CLOJURE_VERSION=1.10.1 diff --git a/build.boot b/build.boot index 5d4c27e..8059b1e 100644 --- a/build.boot +++ b/build.boot @@ -1,4 +1,4 @@ -(def +version+ "0.1.17-SNAPSHOT") +(def +version+ "0.1.17") (set-env! :source-paths #{"src"} @@ -134,7 +134,8 @@ (task-options! tcs/test-cljs {:js-env :phantom} - push {:ensure-branch nil} + push {; :ensure-clean nil + :ensure-branch nil} pom {:project 'mount :version +version+ :description "managing Clojure and ClojureScript app state since (reset)" diff --git a/project.clj b/project.clj index fec536d..581a0b5 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject mount "0.1.17-SNAPSHOT" +(defproject mount "0.1.17" :description "managing Clojure and ClojureScript app state since (reset)" :url "https://github.com/tolitius/mount" :license {:name "Eclipse Public License" diff --git a/src/mount/core.cljc b/src/mount/core.cljc index 00d3aca..871c6eb 100644 --- a/src/mount/core.cljc +++ b/src/mount/core.cljc @@ -284,7 +284,7 @@ (if-not (empty? fs) ;; (mount/start) vs. (mount/start #{}) vs. (mount/start #{1 2 3}) (apply start fs) {:started #{}}) - (let [states (or (seq states) + (let [states (or (->> states (map var-to-str) seq) (all-without-subs))] {:started (bring states up <)})))) @@ -294,7 +294,7 @@ (if-not (empty? fs) ;; (mount/stop) vs. (mount/stop #{}) vs. (mount/stop #{1 2 3}) (apply stop fs) {:stopped #{}}) - (let [states (or (seq states) + (let [states (or (->> states (map var-to-str) seq) (find-all-states)) _ (dorun (map unsub states)) ;; unmark substitutions marked by "start-with" / "swap-states" stopped (bring states down >)] diff --git a/test/core/mount/test/composable_fns.cljc b/test/core/mount/test/composable_fns.cljc index c43e4eb..0ab7692 100644 --- a/test/core/mount/test/composable_fns.cljc +++ b/test/core/mount/test/composable_fns.cljc @@ -109,6 +109,16 @@ (is (= 42 (dval conn))) (mount/stop))) + (testing "swap-states should swap states on start and rollback on stop" + (let [states (swap-states {#'tapp.nyse/conn swap-conn})] + (is (= states (#'mount.core/find-all-states))) + (mount/start #'tapp.nyse/conn) + (is (= 42 (dval conn))) + (mount/stop #'tapp.nyse/conn) + (mount/start #'tapp.nyse/conn) + (is (instance? datomic.peer.LocalConnection (dval conn))) + (mount/stop))) + (testing "swap-states should swap states with states and return only states that it is given" (let [t-states #{"#'is.not/here" #'mount.test.composable-fns/test-conn #'tapp.nyse/conn} states (swap-states t-states {#'tapp.nyse/conn swap-conn