shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
rberger 2021-06-13T02:21:18.008300Z

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?

thheller 2021-06-13T06:28:14.009100Z

@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

👍 1
rberger 2021-06-13T20:48:42.040Z

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)

thheller 2021-06-13T20:52:55.040200Z

yes, thats what the $default does

thheller 2021-06-13T20:53:39.040400Z

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"})

juhoteperi 2021-06-13T08:57:04.011900Z

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 |
--------------------------------------------------------------------------------

thheller 2021-06-13T08:59:30.012500Z

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

thheller 2021-06-13T09:00:16.013100Z

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

juhoteperi 2021-06-13T09:00:29.013700Z

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

thheller 2021-06-13T09:00:32.013800Z

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

juhoteperi 2021-06-13T09:06:58.014400Z

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
--------------------------------------------------------------------------------

thheller 2021-06-13T09:08:34.014900Z

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

👍 1
juhoteperi 2021-06-13T09:16:50.015400Z

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

thheller 2021-06-13T09:48:26.015800Z

fixed in https://github.com/thheller/shadow-cljs/commit/721f71dce7ca55bf9b3c5d80b38709e68270ef4a, released in 2.14.5

💯 2
eoliphant 2021-06-13T15:51:51.022200Z

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.

thheller 2021-06-13T15:54:30.022900Z

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.

thheller 2021-06-13T15:57:09.025600Z

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

eoliphant 2021-06-13T15:59:06.026900Z

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.

eoliphant 2021-06-13T15:59:12.027200Z

ah

eoliphant 2021-06-13T15:59:29.027600Z

ok, yeah will give resolve-var a try

thheller 2021-06-13T15:59:43.027800Z

helper on the cljs side

eoliphant 2021-06-13T15:59:58.028100Z

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

thheller 2021-06-13T16:00:22.028500Z

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

eoliphant 2021-06-13T16:03:06.030700Z

for the helper i tried a couple things someting like:

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

eoliphant 2021-06-13T16:03:50.031700Z

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

thheller 2021-06-13T16:04:26.032200Z

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

eoliphant 2021-06-13T16:04:47.033100Z

firing up my repl now 🙂

thheller 2021-06-13T16:04:49.033200Z

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

thheller 2021-06-13T16:05:33.034500Z

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

eoliphant 2021-06-13T16:05:43.034600Z

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

eoliphant 2021-06-13T16:06:14.035400Z

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

agilecreativity 2021-06-13T16:30:27.037400Z

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

agilecreativity 2021-06-13T16:31:15.037500Z

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")))))

agilecreativity 2021-06-13T16:31:58.037700Z

I am trying out the example project here https://github.com/shadow-cljs/quickstart-browser

thheller 2021-06-13T16:32:35.038Z

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

thheller 2021-06-13T16:32:53.038200Z

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

agilecreativity 2021-06-13T16:33:20.038400Z

Thanks let me check

thheller 2021-06-13T16:33:50.038600Z

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

agilecreativity 2021-06-13T16:36:11.038800Z

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.

agilecreativity 2021-06-13T16:36:50.039Z

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

agilecreativity 2021-06-13T16:39:32.039200Z

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

thheller 2021-06-13T16:47:06.039400Z

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

agilecreativity 2021-06-13T16:55:29.039600Z

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