Fork me on GitHub
#shadow-cljs
<
2024-02-29
>
pez10:02:07

Hello! I want to call a function if a specific namespace is reloaded. Is that possible? Will it be a hook?

thheller10:02:18

whats wrong with just (the-function-you-want-to-call) in that ns?

thheller10:02:46

there is no specific hook to call a function per ns

pez10:02:53

Not following about “what’s wrong with”.

thheller10:02:58

you just put that at the end of the file or something

thheller10:02:12

it'll get called when the namespace is reloaded, just by the nature of being there?

thheller10:02:14

otherwise there is an undocumented feature that might do what you need

pez10:02:35

It would get called in situations when I don’t want it, I think? I do not usually have calls at the top level of the ns.

thheller10:02:20

:devtools {:build-notify a.namespace/a-fn}

thheller10:02:46

basically expecting a (defn a-fn [build-info] ...)

thheller10:02:09

build-info here contains all the info that happening, and includes which namespaces were reloaded

thheller10:02:32

its just data, should be pretty straightforward

pez10:02:27

Thanks. Should be what I need.

lilactown16:02:26

is ^:dev/after-load ns-specific or build-wide?

pez16:02:53

shadow calls all after-load functions from builds that are being watched, not just those that have been reloaded/recompiled.

pez16:02:54

This works great for me, btw:

#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn build-notify!
  "Dev reload utility ..."
  [build-info]
  (when (= :build-complete (:type build-info))
    (when-let [compiled (-> build-info :info :compiled)]
      (when (compiled [:shadow.build.classpath/resource "a/b/c.cljs"])
        #_{:clj-kondo/ignore [:unresolved-namespace]}
        (x.y/do-things!)))))
I have it in my main namespace.

👍 1
henrik13:02:01

As of 2.27.4 , the inspector stalls on “loading…” for EDN and PPRINT outputs. BROWSER seems unaffected.

thheller17:02:36

oops, thx. fixed in master.

👍 1