Fork me on GitHub
#mount
<
2022-12-19
>
Ernesto Garcia11:12:08

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 Garcia11:12:04

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

Ernesto Garcia12:12:24

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

tolitius14:12:52

> 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 Garcia15:12:01

(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

tolitius20:12:53

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