tolitius / mount

managing Clojure and ClojureScript app state since (reset)
Eclipse Public License 1.0
1.23k stars 89 forks source link

Mount doesn't work well with tools.namespace/refresh #18

Closed malchmih closed 8 years ago

malchmih commented 8 years ago

So when I edit some namespace with defstate in it, refresh destroys it completely. Which leads to port is already in use for instance. More info: https://github.com/clojure/tools.namespace#reloading-code-preparing-your-application. Don't know how to solve this.

tolitius commented 8 years ago

@malchmih: I see the problem. It does not really have to do with tools.namespace, but with recompiling the namespace without calling (mount/stop) beforehand.

One way to solve this would be to remember all the states that were stopped, and if a state "was not stopped & it is not brand new", when (mount/start) is called, instead of just starting it, do stop & start.

This would work for both: regular states, and suspendable that are used with (mount/stop-except).

Need to think a bit more about it though. Since stop & start on start for dirty states does not feel clean and expected.

malchmih commented 8 years ago

Great, it's a bit simpler. My first understanding of the problem was depressing :smile: It won't be a showstopper anyway, suspendable states are usually leaves in the the dependency tree. But would be great to solve this :wink:

tolitius commented 8 years ago

@malchmih: ended up being a bit harder than I expected, but harder problems result in more thinking, which is always good.

the idea is to catch dirty states on defstate, and stop them with their stop functions before defining a new state.

the fix is in 0.1.5, let me know if it works for you.

malchmih commented 8 years ago

@tolitius Works great, thank you! Could you upload snapshot to clojars?

tolitius commented 8 years ago

@malchmih great. the snapshot should have the latest, did it not work for you?

malchmih commented 8 years ago

My bad, missed it :smile: