shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
xfyre 2020-11-08T19:14:55.387300Z

Does anyone know what this might mean (React Native)?

(shadow/repl :dev-android)
To quit, type: :cljs/quit
=> [:selected :dev-android]
(def one 1)
=> #object[TypeError TypeError: undefined is not an object (evaluating 'cljs.user.one = (1)')]
I’m pretty certain it was working before, so I don’t quite understand what went wrong and why

thheller 2020-11-08T19:59:27.387800Z

just a hunch but looks like cljs.user is undefined. do you get the same error for (ns cljs.user) or so?

xfyre 2020-11-08T20:39:30.388200Z

oh, interesting. if I execute (ns cljs.user) before anything else - it starts working

thheller 2020-11-08T20:40:23.388600Z

which version is this? there was one 2.10 version that had this problem IIRC

thheller 2020-11-08T20:40:31.388800Z

can't remember which though

xfyre 2020-11-08T20:41:09.389Z

"shadow-cljs": "^2.11.4"

xfyre 2020-11-08T20:42:19.389200Z

it’s no big deal, but I was puzzled

xfyre 2020-11-08T20:45:30.391800Z

@thheller btw - regarding hot reload questions I had a couple of weeks earlier. I figured out why recompilation messes up React Native hot reload. That’s because the entry point file target/index.js gets rewritten every time - so at first Metro reacts correctly and tries to do a fast refresh, but then, when entry point file gets updated - it just reloads the whole thing. Although I finally got it to work as you suggested, I’m wondering whether it would be possible to prevent the entry point from getting recompiled every time.

thheller 2020-11-08T20:50:37.392100Z

you should disable any hot-reloading from the metro side

xfyre 2020-11-08T20:50:45.392600Z

yes, that’s what I did

thheller 2020-11-08T20:50:50.393Z

it is not needed and will only get in the way

xfyre 2020-11-08T20:51:18.393500Z

but I’m curious why the entry point file gets recompiled every time

thheller 2020-11-08T20:51:36.393900Z

so you always have the latest code on disk

thheller 2020-11-08T20:51:52.394300Z

I could disable that but then you'd get old versions if you reloaded the RN app

xfyre 2020-11-08T20:53:06.394600Z

you mean this is configurable?

thheller 2020-11-08T20:53:15.394800Z

no it isn't. but it could be.

thheller 2020-11-08T20:53:33.395200Z

but first I need a convincing reason why it should be 😉

thheller 2020-11-08T20:54:06.396500Z

I mean I can't see a scenarion where metro fast refresh and shadow hot-reload won't conflict with each other and mess each other up

xfyre 2020-11-08T20:55:50.397800Z

it might make sense to allow choosing one or the other (I don’t have a strong opinion about this - since I never got fast refresh to work, I don’t know how convenient it is compared to shadow hot reload)

zhuxun2 2020-11-08T20:57:05.398900Z

It seems that the extern inference doesn't work well with the go blocks:

(defn f
  []
  (.-foo (clj->js {"foo" 42})))
;; WARNING: :infer-warning

(defn f
  []
  (.-foo ^js (clj->js {"foo" 42})))
;; no warning

(defn f
  []
  (clojure.core.async/go (.-foo ^js (clj->js {"foo" 42}))))
;; WARNING again :infer-warning

thheller 2020-11-08T20:57:50.399400Z

yeah thats a known issue. go rewrites too much stuff and loses typehints

zhuxun2 2020-11-08T20:58:42.399900Z

Is there a way to hide that particular warning?

thheller 2020-11-08T20:59:53.400500Z

I don't know. depends on the actual code. I mean if you actually use clj->js and then access a property that doesn't make sense at all?

thheller 2020-11-08T21:00:58.401Z

you should always have as little code as possible in go blocks so ideally you never get to code that has to do this

zhuxun2 2020-11-08T21:04:26.403100Z

What I'm actually trying to do is to wrap http://goog.net.XhrIo.send into a channel so that I don't have to do callbacks

thheller 2020-11-08T21:04:27.403200Z

don't know if there is an open core.async issue about this

thheller 2020-11-08T21:05:38.404200Z

thats fine but you can construct all of it outside a go

zhuxun2 2020-11-08T21:06:52.405400Z

but using this channel requires the user code to be in a go-block, right? That's where I have other code that needs type-hinting

thheller 2020-11-08T21:07:00.405700Z

no it doesnt

thheller 2020-11-08T21:07:26.406500Z

I mean waiting on the channel result does yes but not constructing the xhr itself

zhuxun2 2020-11-08T21:09:01.408Z

I think this is what I mean:

(go
  (let [url (.getParameterValue parsed-href "url")]
      (<! (fetch-ch url))
      ;; other stuff
  ))

zhuxun2 2020-11-08T21:09:39.408600Z

yes, fetch-ch itself wont report any warnings

zhuxun2 2020-11-08T21:09:52.408900Z

but (.getParameterValue parsed-href "url") will

thheller 2020-11-08T21:10:03.409200Z

you can make a helper function for that to avoid the . access

thheller 2020-11-08T21:10:14.409500Z

(let [url (get-parameter-value parsed-href "url")] ...)

👍 1
thheller 2020-11-08T21:10:59.409900Z

I know its annoying but so far no one has dared working on the core.async code

thheller 2020-11-08T21:11:36.410500Z

its not something I can work arround in shadow-cljs

thheller 2020-11-08T21:12:00.411300Z

if you don't care about inference you get (set! *warn-on-infer* false) in that file

zhuxun2 2020-11-08T21:12:46.412300Z

I see. Yeah I guess that's one workaround