mount

Ernesto Garcia 2022-12-19T11:37:08.899489Z

Hi! I am experiencing an issue: After using swap-states , if I selectively stop states with (mount/stop #'my-state) and then start again, the swapped state is still being used. (!!) If I just use (mount/stop) with no arguments, the swapped state is undone correctly, and original states are started afterwards.

Ernesto Garcia 2022-12-19T11:56:04.833599Z

It seems that meta updates done in stop don't work for state vars, and stop is not doing the conversion to strings.

Ernesto Garcia 2022-12-19T12:11:45.448409Z

https://github.com/juxt-forks/mount/tree/fix-stop-with-vars

Ernesto Garcia 2022-12-19T12:19:24.218299Z

There is also a workaround, use (stop (only #'my-state)). Only will transform vars to strings.

tolitius 2022-12-19T14:27:52.928439Z

> stop states with (mount/stop #'my-state) and then start again, the swapped state is still being used. (!!) if you stop and start a state it would be started, yes. can you share a REPL’able example? i.e.

(defstate a …)
(defstate b …)
;;
(mount/stop #'dev/a)
...

Ernesto Garcia 2022-12-19T15:15:01.934439Z

(ns mount-test
  (:require [mount.core :as mount]))

(mount/defstate my-state
  :start (do (println "real start") 1)
  :stop (println "real stop"))

(defn swap-with-fake [states]
  (mount/swap-states states
    {#'my-state {:start (fn [] (do (println "fake start") 2))
                 :stop (fn [] (println "fake stop"))}}))

(comment
  (mount/start (swap-with-fake #'my-state)) ; fake start
  (mount/stop #'my-state) ; fake stop
  (get @@#'mount/meta-state "#'mount-test/my-state") ; !!! origin still there

  (mount/start #'my-state) ; !!! fake start
  (mount/stop) ; fake stop
  (get @@#'mount/meta-state "#'mount-test/my-state") ; origin is nil

  (mount/start #'my-state) ; real start
  (mount/stop)) ; real stop

tolitius 2022-12-19T20:23:53.074689Z

yep, “var vs string” makes sense the https://github.com/tolitius/mount/commit/2d050e9055418982c29ff284d84b60aa4ad6ceda should be in 0.1.17 thanks for the sample to clarify