Fork me on GitHub
#clojurescript
<
2019-07-18
>
talgiat03:07:48

@dnolen I created a minimal example with the bug here: https://github.com/talgiat/cljs-spec-bug. Can’t open a bug in cljs jira (don’t have permission to do so).

Alex Miller (Clojure team)04:07:36

they'll go into the triage queue and we'll turn them into a ticket

oskarkv07:07:01

Is there a good way to turn a DOMRect object into map, without having to list all the attributes?

henryw37416:07:10

would js->clj work?

oskarkv18:07:32

No, because it's not a plain js object

henryw37418:07:41

Ok. js-keys might avoid enumeration

oskarkv19:07:09

Hm, yeah that returned the keys as strings, but then how do I get the values? 😛

henryw37408:07:41

(let [o obj]
 (->> (js-keys o)
    (map #(vec % (goog.object/get o %)
   (into {})
))))

henryw37408:07:49

something like that?

henryw37416:07:51

I'm trying to use the :global-exports feature of foreign-libs and having trouble in this case:

:provides ["@foo/bar"]
      :global-exports '{@foo/bar Bar}
because @foo/bar is not a valid symbol of course and if I put a string instead, that gives me an error 'sym is required'. I'd guess this is a bug, but please let me know if there's something I'm missing. thanks

jamesmintram17:07:31

So I think I found a bug in the compiler, and made a fix that works for me - but unsure it is the right way to fix:

jamesmintram17:07:11

My app.js had the following in it:

jamesmintram17:07:21

document.write('<script src="target\public\cljs-out\common/goog/deps.js"></script>');
document.write('<script src="target\public\cljs-out\common/cljs_deps.js"></script>');
document.write('<script>if (typeof goog == "undefined") console.warn("ClojureScript could not load :main, did you forget to specify :asset-path?");</script>');
document.write('<script>goog.require("figwheel.core");</script>');
document.write('<script>goog.require("figwheel.main");</script>');
document.write('<script>goog.require("figwheel.repl.preload");</script>');
document.write('<script>goog.require("devtools.preload");</script>');
document.write('<script>goog.require("figwheel.main.css_reload");</script>');

jamesmintram17:07:18

the .cljs.edn file had the following setting: :output-dir "target\\public\\cljs-out\\common" (this is on Windows) I'll add that deps.edn made it super easy to download local copies of figwheel and clojurescript + tweak/add debug statements as required.

Stefan19:07:48

I’m looking for help on JS interop, specifically making sure that things also work under advanced compilation. I have found several things at play here, but I don’t understand what each of them do and when/which to use: - ^js type hints - goog.object - cljs.oops - mfikes new bean library

Stefan19:07:52

Is there any documentation that ties this all together? Also, when I find certain things not working, how do I approach debugging this? I’m sprinkling ^js throughout my code atm, and that seems to improve things, but I don’t know if that’s the right way to go.

Stefan19:07:22

(I don’t think it really matters, but this is a shadow-cljs based react-native clojurescript project)

dpsutton19:07:11

usually the first question asked when this stuff happens is for you to give an actual problem statement. are things currently not working under advanced compilation?

Stefan19:07:51

Sure, I’ll give a concrete example, but I’m really looking for general principles more than solutions to specific problems. Like: can I use normal JS interop at all safely? E.g. some react native component calls my callback with a JS object as a parameter and I use normal JS interop notation to access it. Is that OK? Must I include ^js? Is that sufficient? Specifically as an example:

(defn cell [^js details]
  (let [item (.-item details)
  ...))

(defn Staff [styles]
  [:> rn/View styles
   [:> rn/FlatList
    {:data ^js @view-model
     :extra-data ^js @cursor-info
     :key-extractor (fn [item _] (str (.-measureNumber item)))
     :horizontal true
     :Cell-renderer-component ViewOverflow
     :List-header-component #(r/as-element [header])
     :List-footer-component #(r/as-element [footer])
     :Item-separator-component #(r/as-element [separator %])
     :render-item #(r/as-element [cell %])}]])

thheller19:07:20

:data ^js @view-model those don't matter

thheller19:07:20

in this case (.-item details) that will result in details.item in the code. the closure compiler may decide to rename this to something shorter. the ^js hint will cause externs to be added that will prevent the renaming of the .item property (which you need for JS interop)

Stefan19:07:00

Right, and is that a shadow-cljs feature or is that standard CLJS?

thheller19:07:09

standard CLJS (commonly named "externs inference")

👍 4
Stefan19:07:50

Can I infer from that that normally I don’t need to use something like bean or cljs.oops or goog.object directly?

thheller19:07:15

well bean is for different stuff

thheller19:07:21

cljs-oops you don't need yes

Stefan19:07:01

Is there tooling that can warn me about missing ^js type hints? I have run shadow-cljs check but that doesn’t catch everything.

Stefan19:07:58

Ahh now I read that again it starts to make sense, last time I read it, it didn’t yet 🙂

Stefan19:07:49

So as an example, it says:

153 |      :key-extractor (fn [item _] (str (.-measureNumber item)))
---------------------------------------------^----------------------------------
 Cannot infer target type in expression (. item -measureNumber)
-
I change that to:
:key-extractor (fn [^js item _] (str (.-measureNumber item)))
That seems to fix the warning.

thheller19:07:37

yep thats correct

👍 4
Stefan19:07:40

Is there a reason to ever not use :infer-externs :auto?

thheller19:07:25

well the warnings aren't 100% accurate so you may get warnings and add typehints when they aren't actually needed

Stefan19:07:09

At the cost of some performance loss? I can live with that for now 🙂

Stefan19:07:41

And cljs-bean is then probably more like a convenience thing to simplify destructuring JS objects and things like that?

dpsutton19:07:54

(sorry to have mislead earlier. I'm learning new stuff. thanks @stefan.van.den.oord)

Stefan20:07:28

No worries, all help is appreciated! 🙂

👍 4
Stefan20:07:54

Thanks @thheller, extremely insightful and helpful as always. I’ll keep the donation on Patreon active for a while longer 😛

😎 4
Stefan20:07:53

Release build works now 🎉

ivana20:07:25

Hello! Trying to run cljs tests either directly with phantom ....js either thru lein doo there is same error ReferenceError: Can't find variable: Map I find out many things about it in internet, but all of them are not with clojure. What shoud I do?

thheller20:07:40

phantomjs might not support Map which is a new-ish JS hashmap implementation

thheller20:07:01

might need to find out what is using Map or add proper polyfills

ivana20:07:29

I find a lot of examples how to add polyfils , but all of them are in js/ts/etc. How and where I can do it in cljs project?

thheller20:07:24

I think there should be a phantomjs config you can add it too?

thheller20:07:31

not sure in the case of doo

ivana20:07:37

but maybe there is another way for headlesstesting cljs from command line for CI? not unworked phantom, but maybe another V8 source? And not node either

thheller20:07:09

dunno about all the testing options. shadow-cljs has something built-in for karma that some people use

thheller20:07:20

thats all I used in the past

ivana20:07:55

thanks, I'l try to play with phantom config a little and then will look for another way