4 ms·
I have a shortcut, which reloads all modified files, then re-evaluates the previously evaluated expression, within the context of the same namespace it was eval
by onetom 4y ago
I have a shortcut, which reloads all modified files, then re-evaluates the previously evaluated expression, within the context of the same namespace it was evaluated in previously.
This way I can be in any file, modify any `def` of `defn` and see its effect on the expression I'm working on.
After modified something, I might jump to its unit test or jump to some definition of some adjacent vars, where i see a point which I want to probe (with a function like this: `(defn ? [x] (pprint x) x)`).
Then I have 2 modified files, and my cursor is in a 3rd file and the expression I'm iterating on is in a 4th; doesn't matter, I can just keep hitting the same shortcut (Cmd-Ctrl-Enter) to see the effects of my changes on the "expression-under-test".
It's an extremely convenient workflow, which is also easy to teach to ppl!
Downside is that you can't have namespaces, which have side-effects WHEN they are loaded.
To deal with that problem, I'm using `redelay`, `rmap`, `meta-merge` & `defonce`, eg:
(ns service
(:require
[meta-merge.core :refer [meta-merge]]
[gini.rmap :as rmap :refer [rmap ref] :rename {ref $}]
[redelay.core :as redelay])
(def kit
(merge {:cfg {:db/uri "..."}}
(rmap {:db (connect (:db/uri ($ :cfg)))})))
(defonce service-ref
(redelay/state
:start (rmap/valuate!
(meta-merge service/kit
{:cfg {:param 'override}
:some 'special-component}))))
(defn service [] (deref service-ref))
(comment
(.close service-ref)
(-> (service) (some-operation x y z))
)
More info on this topic is here:
https://functionalbytes.nl/clojure/rmap/2020/07/04/rmap-2-update.html https://functionalbytes.nl/clojure/rmap/2020/07/04/rmap-2-up...