Fork me on GitHub
#component
<
2017-09-21
>
josh.freckleton18:09:53

I'm using component and for some reason, no combination of the following is running my latest changes - component/stop - clojure.tools.namespace.repl/refresh (or (refresh :after ...)) - component/start any idea what's up?

noisesmith18:09:46

stop followed by refresh followd by start should work

josh.freckleton18:09:00

i'm using this that I've found:

(defn go []
  (init)
  (start))

(defn reset []
  (stop)
  (refresh :after 'user/go))

noisesmith18:09:13

but if you put any exclusive state (like eg. opening an http port) in the component, and called refresh before stop, then you are stuck

noisesmith18:09:57

because the namespace has been teared down and deconstructed, so you no longer have a convenient handle to the thing monopolizing the resource

donaldball18:09:27

My usual repl recipe is:

(defn init!
  []
  (log/info :msg "Initializing repl system")
  (let [config (config/load-config)]
    (alter-var-root #'system (constantly (system/assemble-system config)))))

(defn start!
  []
  (when-not (:started? system)
    (log/info :msg "Starting repl system")
    (alter-var-root #'system system/start)))

(defn stop!
  []
  (when (:started? system)
    (log/info :msg "Stopping repl system")
    (alter-var-root #'system system/stop)))

(defn restart!
  []
  (stop!)
  (start!))

(defn rebuild!
  []
  (stop!)
  (init!)
  (start!))

josh.freckleton18:09:46

it's weird, manually refreshing after a stop seems to "find" my changed files, at least as far as what gets printed in the repl (cider) but then... it still is running the old code.

josh.freckleton18:09:24

and @donaldball that's basically what I have, pretty close to stuart sierra's recipe

donaldball18:09:20

I dunno, sorry, I don’t really tend to use tools.namespace

noisesmith18:09:13

@josh.freckleton what if you use load-file or require with the :reload arg, does that change things where refresh does not?

noisesmith18:09:29

if so, it could be that tools.namespace is confused or misconfigured

danielcompton20:09:54

@josh.freckleton sometimes I find tools.namespace gets really stuck and I have to call c.t.n.repl/clear to reset things

danielcompton20:09:00

Also, are you using lein or boot?

josh.freckleton20:09:27

@danielcompton I'm on lein, I'll have to look into clear, thanks! It sounds like that's what's going on and I'm not sure why!

danielcompton21:09:15

also reloaded.repl is great for standardising all of the behaviour above ^^

danielcompton21:09:23

pretty much the same but nice to have in a library, at least I like it