Fork me on GitHub
#shadow-cljs
<
2021-06-13
>
rberger02:06:18

Codox seems to be barfing on the :default in :require that shadow-cljs enables. Does anyone know a way to tell codox to allow it? The error is:

Caused by: clojure.lang.ExceptionInfo: Only :as, :refer and :rename options supported in :require / :require-macros; offending spec: ["react-bootstrap-table2-editor" :default cellEditFactory] at line 1 file:/Users/rberger/omnyway/neo/lib/re-view/src/review/table.cljs {:file #object[java.net.URL 0x1835b24b "file:/Users/rberger/omnyway/neo/lib/re-view/src/review/table.cljs"], :line 1, :column 1, :tag :cljs/analysis-error}
Or is my only painful alternative is to replace the very nice :default with :as and an alias?

thheller06:06:14

@rberger you can use the new official alternative ["react-bootstrap-table2-editor$default" :as cellEditFactory], see https://clojurescript.org/news/2021-04-06-release#_library_property_namespaces

👍 2
rberger20:06:42

If I use the new official alternative, do I use the alias in the code just like it was the previous :default? I.e (cellEditFactory (clj->js {:mode "click"})) (without the /default)

thheller20:06:55

yes, thats what the $default does

thheller20:06:39

FWIW don't do this (cellEditFactory (clj->js {:mode "click"})). for really simple JS objects like that just use #js eg. (cellEditFactory #js {:mode "click"})

juhoteperi08:06:04

I'm getting bunch of infer-warnings on shadow-cljs with Reagent (the project itself, not when using as library). Seems to be related to deftype and extending a protocol without any methods. Though IAtom doesn't cause these problems, any ideas?

(defprotocol IReactiveAtom)

(deftype IRatom [bar]
  IAtom
  IReactiveAtom
  )
------ WARNING #1 - :infer-warning ---------------------------------------------
 File: /home/juho/tmp/your-project/src/your_project/core.cljs:30:1
--------------------------------------------------------------------------------
  27 |
  28 | (defprotocol IReactiveAtom)
  29 |
  30 | (deftype Ratom [bar]
-------^------------------------------------------------------------------------
 Cannot infer target type in expression (. (. IRatom -prototype) -your-project$core$IReactiveAtom$)
--------------------------------------------------------------------------------
  31 |   IAtom
  32 |   IReactiveAtom
  33 |   )
  34 |
--------------------------------------------------------------------------------

thheller08:06:30

most likely a problem in CLJS directly? or does it not happen there?

thheller09:06:16

would help if you try with cljs.main and (set! *warn-on-infer* true)

juhoteperi09:06:29

No, but I guess I need to check if I'm running warn-on-infer there.

thheller09:06:32

if that doesn't warn I can fix it. if not its happening somewhere in the CLJS parts of inference

juhoteperi09:06:58

Strange, I get different warnings with cljs.main:

Compiling /home/juho/Source/reagent/src/reagent/ratom.cljs to target/bundle-adv/resources/public/js/out/reagent/ratom.js
WARNING: Cannot infer target type in expression (. c push derefed) at line 76 /home/juho/Source/reagent/src/reagent/ratom.cljs
WARNING: Cannot infer target type in expression (. G__6105 push p2__6103#) at line 98 /home/juho/Source/reagent/src/reagent/ratom.cljs
WARNING: Cannot infer target type in expression (. G__6105 push p3__6104#) at line 98 /home/juho/Source/reagent/src/reagent/ratom.cljs
WARNING: Cannot infer target type in expression (. v -destroy) at line 328 /home/juho/Source/reagent/src/reagent/ratom.cljs
WARNING: Cannot infer target type in expression (. a push f) at line 495 /home/juho/Source/reagent/src/reagent/ratom.cljs
And shadow-cljs:
------ WARNING #1 - :infer-warning ---------------------------------------------
 File: /home/juho/Source/reagent/src/reagent/ratom.cljs:129:1
--------------------------------------------------------------------------------
 126 |
 127 | (defprotocol IReactiveAtom)
 128 |
 129 | (deftype RAtom [^:mutable state meta validator ^:mutable watches]
-------^------------------------------------------------------------------------
 Cannot infer target type in expression (. (. RAtom -prototype) -reagent$ratom$IReactiveAtom$)
--------------------------------------------------------------------------------
 130 |   ; IAtom
 131 |   IReactiveAtom
 132 |
 133 |   IEquiv
--------------------------------------------------------------------------------

------ WARNING #2 - :infer-warning ---------------------------------------------
 File: /home/juho/Source/reagent/src/reagent/ratom.cljs:208:1
--------------------------------------------------------------------------------
 205 |                 (set! (.-reaction obj) r))
 206 |               v))))
 207 |
 208 | (deftype Track [f args ^:mutable reaction]
-------^------------------------------------------------------------------------
 Cannot infer target type in expression (. (. Track -prototype) -reagent$ratom$IReactiveAtom$)
--------------------------------------------------------------------------------
 209 |   IReactiveAtom
 210 |
 211 |   IDeref
 212 |   (-deref [this]
--------------------------------------------------------------------------------

------ WARNING #3 - :infer-warning ---------------------------------------------
 File: /home/juho/Source/reagent/src/reagent/ratom.cljs:250:1
--------------------------------------------------------------------------------
 247 |
 248 | ;;; cursor
 249 |
 250 | (deftype RCursor [ratom path ^:mutable reaction
-------^------------------------------------------------------------------------
 Cannot infer target type in expression (. (. RCursor -prototype) -reagent$ratom$IReactiveAtom$)
--------------------------------------------------------------------------------
 251 |                   ^:mutable state ^:mutable watches]
 252 |   IAtom
 253 |   IReactiveAtom
 254 |
--------------------------------------------------------------------------------

------ WARNING #4 - :infer-warning ---------------------------------------------
 File: /home/juho/Source/reagent/src/reagent/ratom.cljs:358:1
--------------------------------------------------------------------------------
 355 | ;; - state
 356 | ;; - watches
 357 | ;; - watching
 358 | (deftype Reaction [f ^:mutable state ^:mutable ^boolean dirty? ^boolean nocache?
-------^------------------------------------------------------------------------
 Cannot infer target type in expression (. (. Reaction -prototype) -reagent$ratom$IReactiveAtom$)
--------------------------------------------------------------------------------
 359 |                    ^:mutable watching ^:mutable watches ^:mutable auto-run
 360 |                    ^:mutable caught]
 361 |   IAtom
 362 |   IReactiveAtom
--------------------------------------------------------------------------------

thheller09:06:34

that is odd. thx for testing, I'll look into it

👍 3
juhoteperi09:06:50

Minimal project https://github.com/Deraen/shadow-cljs-infern-warning, npm run release shows the warning, build.sh doesn't

eoliphant15:06:51

hello, i’ve a quick question. I’m trying to create a devcards macro that basically just wraps components with my react lib’s theme provider, and realized it presents a bit of a catch 22 as i need the symbol for the react component in the actual clj implementation. i know the general approach is to make sure you use fully qualified symbols (clojure.core/xxx). But since the ["mylib" :default/refer …] syntax is cljs/shadow specific, just wondering what (if any) equivalent there is.

thheller15:06:30

create a helper function that does what you need. (defn foo-helper [a b] (that-npm-alias/do-stuff a b)). maybe even helps reducing the amount of code the macro generates.

thheller15:06:09

you can also use cljs.analyzer/resolve-var to get the actual alias if helper function is not an option

eoliphant15:06:06

a helper on the clj side? I tried something like that w/o creating the macro, for something like (defcard xxx (wrap-theme comp)) but I think the arg capture confuses things.

eoliphant15:06:29

ok, yeah will give resolve-var a try

thheller15:06:43

helper on the cljs side

eoliphant15:06:58

yeah, that’s what I did. no joy 😉

thheller16:06:22

what did you try? should be straightforward macro-wise? even just a function?

eoliphant16:06:06

for the helper i tried a couple things someting like:

(defn theme
   [x]
   [:> ThemeProvider 
     x])
as well as another variant that returned an fn

eoliphant16:06:50

but i hadn’t gotten far on the macro, as I realized i wasn’t sure how to fully qualify ThemeProvider

thheller16:06:26

(:name (cljs.analyzer/resolve-var &env the-sym))

eoliphant16:06:47

firing up my repl now 🙂

thheller16:06:49

but that doesn't look like it should be a macro

thheller16:06:33

(remember that you can't write macros in a CLJS repl)

eoliphant16:06:43

yeah i didn’t think so, but for whatever reason it doesn’t seem to work. will try checking the macro expansion

eoliphant16:06:14

ah yeah i know, just meant to start playing with the analyzer

agilecreativity16:06:27

Hi, I keep getting shadow-cljs - Stale Output! Your loaded JS was not produced by the running shadow-cljs instance. Is the watch for this build running message when trying from Emacs cider-jackin-cljs

agilecreativity16:06:15

What option do I miss? My .dir-locals.el looks like

((nil . ((cider-preferred-build-tool . shadow-cljs)
         (cider-default-cljs-repl . shadow)
         (cider-shadow-default-options . "app")
         (cider-shadow-watched-builds . ("app")))))

thheller16:06:35

either you are loading the wrong javascript (often happens when people rename :modules or change :output-dir)

thheller16:06:53

or you might have 2 instances of shadow-cljs running competing with each other and conflicting

agilecreativity16:06:20

Thanks let me check

thheller16:06:50

note that jack-in from emacs starts a new fresh instance, so if you have shadow-cljs watch already running separately that would be your conflict

agilecreativity16:06:11

I am sure I don’t have anything running as I list all of my open program and then kill off all node process just to make sure and I am still getting the error.

agilecreativity16:06:50

And I kill off my Emacs instance as well just to be on the clean state for testing.

agilecreativity16:06:32

I am trying the npx shadow-cljs watch app then cider-connect options to confirm

thheller16:06:06

shadow-cljs is a java process. so killing the node process may not end up killing the java process

agilecreativity16:06:29

I managed to fix it by reload the page. And the things seems to be connect properly now. Thanks again for your help.