Fork me on GitHub
#nbb
<
2023-02-03
>
alpox11:02:47

I tried to use loadFile to get access to functions from clojure which worked fine so far. However in my usecase js loads cljs from index.mjs , cljs then loads other javascript files which themselves access other parts of the cljs. It works apart from that apparently everything in the cljs files gets re-evaluated and iā€™m loosing atom states as the atoms are re-defined. Is this a usecase that is generally not supported by nbb or is there a better way for js/cljs communication?

borkdude11:02:35

It's better to use require than loadFile

borkdude11:02:01

you can use loadString in the JS API to execute a require expression

borkdude11:02:15

But only the .cljs file that you load with loadFile should be reloaded, not the ones it requires - if they are already loaded, then they should not be reloaded

alpox11:02:45

Ah many thanks. This works!

const { register } = await loadString("(require '[test.registry :as r]) #js {:register r/register}");
although a bit verbose. Would a separate API-file for the use with loadFile be ill-adviced?

borkdude11:02:17

Can you confirm that when using loadString on the first cljs file, does not reload the other cljs files? If it does, then it's a bug

borkdude11:02:28

I first want to get that out of the way before I answer other questions

alpox11:02:14

Yes, I confirm. Like this it does not re-evaluate the namespace registry whereas when using loadFile directly on the file for the namespace it did re-evaluate it.

borkdude11:02:17

That's not what I meant. I expect re-evaluation of the file argument to loadFile but not to its transitive dependencies

borkdude11:02:12

I don't think adding a JS API thing for everything is possible, but maybe we can document this.

alpox11:02:43

Sorry, I misunderstood then. I did some tests with loadFile to see if transitive dependencies were re-evaluated and can confirm they are not.

šŸ‘ 1
alpox11:02:32

With the JS-API thing I meant that with this behavior I can (in this project) make a separate js-api cljs namespace only for the use from javascript and then load only that one with loadFile

borkdude11:02:26

oh yes, that would work too

alpox11:02:45

Awesome, thats actually quite clean:

const { register, parseTable } = await loadFile("src/api.cljs");
Thanks for your help šŸ™‚

šŸ™Œ 1