parent
c19ef8af9a
commit
f98df5b2c4
3 changed files with 19 additions and 6 deletions
|
|
@ -421,13 +421,16 @@ Switched to branch 'suspendable'
|
||||||
Mount will detect when a namespace with states (i.e. with `(defstate ...)`) was reloaded/recompiled,
|
Mount will detect when a namespace with states (i.e. with `(defstate ...)`) was reloaded/recompiled,
|
||||||
and will check every state in this namespace whether it was running at the point of recompilation. If it was, _it will restart it_:
|
and will check every state in this namespace whether it was running at the point of recompilation. If it was, _it will restart it_:
|
||||||
|
|
||||||
* will invoke its `:stop` function that was there _before_ the recompilation
|
* if a state has a `:stop` function, mount will invoke it on the old version of state (i.e. cleanup)
|
||||||
* will invoke its new `:start` function _after_ this state is recompiled/redefined
|
* it will call a "new" `:start` function _after_ this state is recompiled/redefined
|
||||||
|
|
||||||
Mount won't keep it a secret, it'll tell you about all the states that had to be restarted during namespace reload/recompilation:
|
Mount won't keep it a secret, it'll tell you about all the states that had to be restarted during namespace reload/recompilation:
|
||||||
|
|
||||||
<img src="doc/img/ns-recompile.png" width="500px">
|
<img src="doc/img/ns-recompile.png" width="500px">
|
||||||
|
|
||||||
|
Providing a `:stop` function _is_ optional, but in case a state needs to be cleaned between restarts or on a system shutdown,
|
||||||
|
`:stop` is highly recommended.
|
||||||
|
|
||||||
## Affected States
|
## Affected States
|
||||||
|
|
||||||
Every time a lifecycle function (start/stop/suspend/resume) is called mount will return all the states that were affected:
|
Every time a lifecycle function (start/stop/suspend/resume) is called mount will return all the states that were affected:
|
||||||
|
|
|
||||||
|
|
@ -48,9 +48,10 @@
|
||||||
this function stops this 'lost' state instance.
|
this function stops this 'lost' state instance.
|
||||||
it is meant to be called by defstate before defining a new state"
|
it is meant to be called by defstate before defining a new state"
|
||||||
[state]
|
[state]
|
||||||
(when-let [stop (@running state)]
|
(when-let [{:keys [stop] :as up} (@running state)]
|
||||||
(prn (str "<< stopping.. " state " (namespace was recompiled)"))
|
(when stop
|
||||||
(stop)
|
(prn (str "<< stopping.. " state " (namespace was recompiled)"))
|
||||||
|
(stop))
|
||||||
(swap! running dissoc state)
|
(swap! running dissoc state)
|
||||||
{:restart? true}))
|
{:restart? true}))
|
||||||
|
|
||||||
|
|
@ -90,7 +91,7 @@
|
||||||
(record! state resume done)
|
(record! state resume done)
|
||||||
(record! state start done)))]
|
(record! state start done)))]
|
||||||
(alter-state! current s)
|
(alter-state! current s)
|
||||||
(swap! running assoc state stop)
|
(swap! running assoc state {:stop stop})
|
||||||
(update-meta! [state :status] #{:started}))))
|
(update-meta! [state :status] #{:started}))))
|
||||||
|
|
||||||
(defn- down [state {:keys [stop status] :as current} done]
|
(defn- down [state {:keys [stop status] :as current} done]
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,15 @@
|
||||||
(mount/stop)
|
(mount/stop)
|
||||||
(is (instance? mount.core.NotStartedState (dval tapp.example/nrepl))))))
|
(is (instance? mount.core.NotStartedState (dval tapp.example/nrepl))))))
|
||||||
|
|
||||||
|
#?(:clj
|
||||||
|
(deftest start-on-recompile
|
||||||
|
(let [_ (mount/start)
|
||||||
|
before (dval tapp.conf/config)]
|
||||||
|
(require 'tapp.conf :reload)
|
||||||
|
(is (not (identical? before (dval tapp.conf/config)))) ;; should be a newly recompiled map
|
||||||
|
(mount/stop)
|
||||||
|
(is (instance? mount.core.NotStartedState (dval tapp.conf/config))))))
|
||||||
|
|
||||||
#?(:cljs
|
#?(:cljs
|
||||||
(deftest cleanup-dirty-states
|
(deftest cleanup-dirty-states
|
||||||
(let [_ (mount/start #'mount.test.helper/helper)]
|
(let [_ (mount/start #'mount.test.helper/helper)]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue