Fork me on GitHub
#shadow-cljs
<
2023-07-08
>
nivekuil18:07:33

I need some help understanding shadow.loader/load. If I load a module with the ns app.foo, and in the promise callback I immediately call a function which assumes that ns has been require'd like fulcro's (comp/registry-key->class app :app.foo/Class), it returns nil. but it does work if I manually add a delay. why is this part async, and can I wait for it?

thheller07:07:10

I don't really understand the question. the loading of the module is async, so if you await that all code will be available

thheller07:07:26

what the code in question does is however a totally different question

thheller07:07:46

I don't know what comp/registry-key->class is or does, so I cannot really answer your question

nivekuil18:07:43

hadn't seen shadow.lazy, thanks for saving me the trouble of understanding yet another problem 😄

nivekuil18:07:59

comp/registry-key->class is called as part of the defsc macro, which defs something and swaps a global atom that should contain the keyword corresponding to the def'd symbol

nivekuil18:07:55

actually I just realized my mistake: shadow.loader uses a goog.async.deferred, not a promise, I'm using promesa not the interop api so nothing was being awaited... oops

nivekuil18:07:34

only noticed once the module got fat enough and never questioned that old assumption until now

thheller18:07:42

they still have a .then, so act like any promise?

nivekuil18:07:35

evidently not, but too lazy to dive into promesa's p/letimplementation to figure out why

nivekuil18:07:34

for future reference it's easy to convert:

(let [p (p/deferred)]
  (lazy-loader/load lazy-load (fn [x] (p/resolve! p x)))
  p)