nbb

alpox 2023-02-03T11:08:47.107569Z

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?

borkdude 2023-02-03T11:09:35.321029Z

It's better to use require than loadFile

borkdude 2023-02-03T11:10:01.235939Z

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

borkdude 2023-02-03T11:11:15.407529Z

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

alpox 2023-02-03T11:18:45.040939Z

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?

borkdude 2023-02-03T11:20:17.336329Z

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

borkdude 2023-02-03T11:20:28.014239Z

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

alpox 2023-02-03T11:21:14.242449Z

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.

borkdude 2023-02-03T11:22:17.216409Z

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

borkdude 2023-02-03T11:23:12.617199Z

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

alpox 2023-02-03T11:29:43.951499Z

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
alpox 2023-02-03T11:31:32.834979Z

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

borkdude 2023-02-03T11:32:26.128519Z

oh yes, that would work too

alpox 2023-02-03T11:36:45.603409Z

Awesome, thats actually quite clean:

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

šŸ™Œ 1