This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-01-24
Channels
- # adventofcode (1)
- # announcements (22)
- # babashka (30)
- # beginners (69)
- # calva (53)
- # cider (17)
- # cljfx (1)
- # clojure (2)
- # clojure-australia (1)
- # clojure-europe (1)
- # clojurescript (36)
- # code-reviews (10)
- # conjure (3)
- # cursive (2)
- # datomic (4)
- # fulcro (13)
- # graalvm (261)
- # luminus (2)
- # malli (1)
- # nrepl (13)
- # off-topic (19)
- # rdf (3)
- # reveal (1)
- # ring (3)
- # sci (66)
- # shadow-cljs (14)
- # spacemacs (1)
- # specmonstah (1)
- # test-check (1)
- # vim (2)
- # xtdb (14)
I’d like to implement require but lazy load a :namespace
map compiled to cljs instead of a Clojure source file, is this possible?
looking at https://github.com/borkdude/sci/blob/19242bf2cf549fd7895696e65761c04e32c61f7f/src/sci/impl/evaluator.cljc#L193 it seems it’s not but seems easy enough to add. Would a PR be welcome for it?
@borkdude I want to load an cljs advanced compiled module, basically merge the namespaces map on load
so basically load https://github.com/sicmutils/sicmutils/blob/master/src/sicmutils/env/sci.cljc#L105 lazily but having it part of my advanced compiled bundle (but as a separate module)
@mkvlr ah, yeah, I think you can mis-use :load-fn
for this by checking the namespace, then updating your ctx manually and then return an empty source string
(update ctx :env swap! assoc-in [:namespaces your-ns-name] your-ns)
something like this@borkdude returning an empty source and changing the env works. But I still need a async variant of :load-fn
. https://github.com/borkdude/sci/issues/511
@mkvlr if this is going to be async, how do you prevent using the required namespace in successive expressions?
I was thinking, maybe you can fire the async operation and then wait in some loop until the async operation has completed?
is something like this not possible? async operation -> marks flag when done loop { wait for flag to become true }
I'm not sure what the consequences will be if load-fn has an async counterpart. Will then everything become async?
https://eloquentjavascript.net/11_async.html says: > If we had used the handler’s return value as the response value, that would mean that a request handler can’t itself perform asynchronous actions. A function doing asynchronous work typically returns before the work is done, having arranged for a callback to be called when it completes. So we need some asynchronous mechanism—in this case, another callback function—to signal when a response is available.
So an alternative would be to include the module inside some dom node or JS variable as a string and load it from there maybe? Or will this have negative consequences?
Isn't is possible to get synchronous loading by creating a dom node which refers to that file and then reading the contents from that dom node?
a dom node which does a GET request and gets populated with a string response from your server
I think it’s just not possible to do async work from a non-async function or do I have a fundamental misunderstanding?
it will block your UI, but for require I think it's reasonable, since this is what happens in CLJ too
pretty sure that @thheller made cljs_eval
return a promise for the same reason: https://github.com/thheller/shadow-cljs/blob/206d4029a80afa267835782516a9cb8eca92e8bf/src/main/shadow/cljs/devtools/client/shared.cljs#L424-L452
of course, but for loading a namespace from an external resource, I don't think it's unreasonable to show a spinner and wait for it to be loaded. it simplifies the model drastically
> Just because appendChild() has returned does not in anyway guarantee that the script has finished executing He is talking about the JS eval
so what would happen if you wrapped the sync sci API functions in your own async functions?
so any eval string you do would be async and the string could be coming from an http request?
would that be problematic when you eval code that does the require
and uses it in the same cell?