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?
It's better to use require than loadFile
you can use loadString in the JS API to execute a require expression
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
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?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
I first want to get that out of the way before I answer other questions
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.
That's not what I meant. I expect re-evaluation of the file argument to loadFile but not to its transitive dependencies
I don't think adding a JS API thing for everything is possible, but maybe we can document this.
Sorry, I misunderstood then. I did some tests with loadFile to see if transitive dependencies were re-evaluated and can confirm they are not.
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
oh yes, that would work too
Awesome, thats actually quite clean:
const { register, parseTable } = await loadFile("src/api.cljs");
Thanks for your help š