Hi everyone! Like many of you I'm reading the "Web Development with Clojure" book, and I'm a bit confused about the usage of the mount library in chapter 3. The motive for using something like mount is clear to me. What's confusing is how these states are being started. The book mentions that to "start" a state defined with defstate you just need to require it into your namespace which makes sense to me. What isn't clear is that the core namespace main function starts with
(mount/start #'guestbook.config/env)
Why do we have to explicitly start the env state if it's already required into the core namespace?> The book mentions that to "start" a state defined with defstate you just need to require it into your namespace
That isn't the whole story. I'm not sure what the book says exactly, but requiring the namespace with a defstate
inside is not everything you need to do.
Requiring the namespace just registers the state definition with mount (it "defines" the state). However the start
lifecycle function is not called automatically merely by requiring the namespace.
states in mount are not started until mount/start
is called.
I have the 2nd edition of the book and it says: > For example, if namespace A contains a resource and depends on namespace B, which contains another resource, then state B will be started before state A. ..which may be the bit that's tripping you up? Mount can figure out which states depend on other states based on the order in which namespaces are required, but it doesn't automatically start them. You've got to do that explicitly somewhere, usually manually in a REPL during dev time, or in your main function in production.