Fork me on GitHub
#shadow-cljs
<
2020-10-12
>
currentoor15:10:59

Has anyone used apollo client with shadow-cljs? Or does lack of webpack prevent that from working.

thheller15:10:35

does it explicitely depend on webpack?

zilti15:10:45

Are there really libs that actually do? I've seen some libs that claim to require webpack (by mentioning it as part of their install) but none of these actually did. Actually depending on it sounds like terrible design...

thheller16:10:48

some are rather webpack specific yes but not that common in popular libs

flyboarder17:10:29

Anyone using dynamic loading (shadow.loader) with or without shadow.lazy?

flyboarder17:10:59

I have a module with an init-fn that fn loads a module dynamically, but im having issues calling things from the loaded module

flyboarder17:10:07

:module-loader true
:modules {:base   {:entries [app.debug app.auth]}
          :common {:entries [app.index]
                   :depends-on #{:base}}
          :app {:init-fn app.main/init!
                :depends-on #{:common}}
          :cloud {:entries [app.main.cloud]
                  :depends-on #{:app}}}

thheller17:10:37

I'm assuming this doesn't actually say :cloud {:entities?

flyboarder17:10:45

that could very well be a typo

flyboarder17:10:54

I was tired lastngiht

flyboarder17:10:31

I had that module as an init-fn as well as a test

flyboarder18:10:32

when using it as an init-fn it loaded - but I got a whole bunch of errors that things were already declared

flyboarder18:10:58

;; app/main.cljs
(defn init! []
  (loader/with-module :cloud
    (fn []
      (let [cloud (resolve 'app.main.cloud/dashboard)]
        (cloud)))))

flyboarder18:10:27

failed to load clojure.set.js Error: Namespace "clojure.set" already declared.

thheller18:10:09

hmm don't use with-module?

thheller18:10:38

(-> (loader/load :cloud) (.then (fn [] ...))

thheller18:10:28

I can't remember what with-module is for

thheller18:10:54

also just use shadow.lazy. much better API and doesn't involve dealing with resolve issues

flyboarder18:10:56

Ideally I want to use shadow.lazy but It couldnt find the modules

thheller18:10:31

what does that mean?

flyboarder18:10:35

when I give it the symbol the compiler throws an error about not finding the app.main.cloud module

flyboarder18:10:48

to the loadable

flyboarder18:10:50

(def components
  (lazy/loadable {:cloud app.main.cloud/dashboard)})

(defn init! []
  (-> (lazy/load components)
      (.then
        (fn [{:keys [cloud]}]
            (cloud)))))

thheller18:10:22

well if you actually had the typo from earlier that may have been the cause?

thheller18:10:42

I mean if the ns isn't actually included in the build?

flyboarder18:10:33

So the block above does work, but I still get the same console errors

flyboarder18:10:10

ill check the manifest again

thheller18:10:04

also note that if you are loading the module directly on init it would be better to have your HTML load it immediately instead

thheller18:10:35

but otherwise this looks fine

flyboarder18:10:44

base.js:2226 failed to load goog.dom.inputtype.js Error: Namespace "goog.dom.InputType" already declared.

flyboarder18:10:06

is the depends-on correct? should the dynamic modules “depend” on the main loader module, or the other way around?

flyboarder18:10:35

this seems to be thrown by the dynamic module

thheller18:10:19

try triggering the load via some kind of async delay

thheller18:10:46

(js/setTimeout (fn [] _here_ ) 0) or so

thheller18:10:59

maybe its a race condition

flyboarder18:10:17

ok so i reduced the number of them by removing the module from the index file

thheller18:10:51

don't know what that means

flyboarder18:10:13


<html>
<body>
<script src="./client/base.js"></script>
<script src="./client/common.js"></script>
<script src="./client/app.js"></script>
</body>
</html>

flyboarder18:10:16

thats the index file

flyboarder18:10:26

I had the cloud.js in there

thheller18:10:28

ah yeah if you do that you definitely need the timeout

thheller18:10:33

otherwise it triggers the load twice

flyboarder18:10:05

so im still getting some of them

thheller18:10:31

I don't like that you have ./client as the path. much more predictable if you use absolute paths with the proper absolute :asset-path as well

flyboarder18:10:54

yeah thats an issue with the kubernetes ingress

thheller18:10:58

but besides that I don't have enough information to help

thheller18:10:32

it all looks fine from here

flyboarder18:10:49

ok good to know im at least kinda understanding this 😅

flyboarder18:10:55

doing it with the lazy block as above seems to be working now, could very well have been a typo causing the issue with it last night