Fork me on GitHub
#shadow-cljs
<
2023-01-12
>
pbaille16:01:01

Hello everyone, I'm trying to execute some code in a build-hook (:compile-prepare stage) that need to know which namespaces will be recompiled, or at least which namespace has triggered the hot-reloading. I cannot find this information in the build-state that my hook receives. Does anyone has an idea ? thank you.

thheller17:01:36

define "execute some code"?

pbaille17:01:42

I have to tweak expansion time state for some macros

thheller17:01:03

that doesn't sound like a good idea?

thheller17:01:00

the set of sources that will be recompiled you can get by inspecting :build-sources, which is a vector of resource-ids. if there is a corresponding (get-in build-state [:output resource-id]) it won't be recompiled. otherwise it will be

pbaille17:01:04

maybe 🙂 but I cannot think of an alternative, I've got an atom that hold some kind of environment to be used in expansions depending on the targetting platform.

thheller17:01:22

that sound really bad 😛

pbaille17:01:30

haha but really fun

thheller17:01:43

if you want to expand on what you trying to do I can maybe make suggestions

thheller17:01:14

an atom is not tracked or restored with caching in mind

thheller17:01:43

so builds may become unpredictable with the state of the atom and cache in mind. unless of course you disable all caching, which again is really bad 😉

pbaille17:01:11

Yes disable caching entirely sound like a bad idea on the long run

thheller17:01:21

oh and you can get more information about the source that is getting recompiled via (get-in build-state [:sources resource-id])

thheller17:01:57

but I repeat that any side-effected state during compilation is not a good idea 😉

pbaille17:01:16

The issue is on hot-reloading only

pbaille17:01:38

Yes but I cannot find a better way to do what I want for now. I will try to explain what I'm trying to achieve better in order for you to be able to do wise suggestions 🙂

pbaille17:01:58

It is a library that aims to let me define and implement protocols in a cross-platform way (clj and cljs) without reader conditionals. For being able to do this I need to keep track of which type implements which methods and things like this. It is clearly a bad idea but its almost done and I would like to fix this hot-reloading issue (on the first compilation everything works) .

thheller17:01:39

hmm but how do you track protocol implementations? I mean how would you "find" reify?

pbaille17:01:42

I'm not tracking reified things and do not intend to do so, I do not track already existing protocols neither. When a new method is defined using one of my macro, I capture all informations in my expansion-time state. In addition to that, I store all "prototypes" in a runtime atom, that can be used to share method implementations. Its kind of baroque I agree but I works like I want for now.

pbaille18:01:04

I think that the information that you gave to me will allow me do what I need, so thank you a lot !

Sam Ritchie20:01:00

question - I’m writing a cljs macro and want to be able to reference something from box given

(:require ["mathbox-react" :as box]
            [reagent.core :as r])

Sam Ritchie20:01:38

is there a way to make a “fully qualified” symbol with a string namespace? I am not sure how to get the alias to resolve, since the macro is expanded on the clojure side

thheller20:01:15

its best to just make a wrapper function and call that from the macro. So in the CLJS part (defn get-me-the-thing [] box/foo) or whatever.

Sam Ritchie20:01:40

I am trying to build the core there from a symbol, like Group ; (def Group (reagent.core/adapt-react-class box/Group) , basically

Sam Ritchie20:01:09

so I can write (defprim Group <some-map-that-I-will-turn-into-a-docstring>)

Sam Ritchie21:01:56

oh, it’s easier to go the other way… (defprim box/Group ) and then strip off the namespace for the symbol I feed to def