Fork me on GitHub
#clojurescript
<
2020-03-08
>
folcon01:03:55

I’ve been using records in clj-land and converting them into maps to send in cljs-land, because edn doesn’t handle records. I’ve been using records because most of the material I’ve read couples that with protocols. Now I’m hitting what appear to be slowdowns entirely due to conversion, should I: 1) Use transit or some flavor of that (not sure how this works with records) 2) Hand write custom conversion functions 3) Be just using raw maps and multimethods 4) Be doing this all some other way The cljs side code doesn’t care other than what it gets sent is maplike, as all it needs to do is render it. The clj side does need to be able to do some dispatch based stuff as I am periodically processing the datastructure to get my next state. This is happening over sente if that helps… I’ve spent some time looking at , but not sure if I should be spending time converting that to cljc.

potetm02:03:22

@folcon From my own experience: just don’t put records on the wire.

potetm02:03:23

My first followup is: are protocols really necessary, or will a multimethod suffice?

potetm02:03:00

depends on the use case, but many folks reach for the former far too soon

potetm02:03:32

if you really need protocols, I would consider record->hashmap->wire->hashmap->record

folcon02:03:29

Ok, well that answers that =)… I don’t need records, however pretty much all the stuff you see online talks up records+protocols over multimethods, and much of the time the framing appears to be why oh why would you ever use multimethods, they’re just a poor man’s protocol…

potetm04:03:23

@folcon Curious what you’re seeing. Generally speaking, the opposite is true.

potetm04:03:11

more concretely: protocols: theoretically faster, more limited (can only dispatch on type of the first arg), can syntactically group a few fn together (e.g. push and pop on an IQueue protocol)–though there is no guarantee that all fns will be implemented multimethods: theoretically slower, more flexible (can dispatch on anything), no syntactic grouping (but you can group by convention or document a grouping)

Old account11:03:12

how to add externs to all :cljsbuild builds?

folcon12:03:23

@potetm, probably reading this in different places to you =)… What I’m working on here is more in gamedev/sim space and it seems most of the things I’ve seen frame it the way I’ve described, default I’ve seen is records/protocols =)…

roklenarcic14:03:43

Does anyone have any experience with scanning QR codes? I’ve tried react-qr-reader which I’ve managed to make work, but the worker fails to recognize any of QR codes I’ve tested it with… I’ve tried to have it scan the QR code from the wikipedia article on QR codes and it failed to detect that. Does anyone have any particular JS QR code reader library they like?

dangercoder19:03:27

Has anyone worked with puppeteer and clojurescript? Im getting this issue when trying to write clojurescript in page.eval() Error: Evaluation failed: ReferenceError: cljs is not defined   `at puppeteer_evaluation_script__:4:1` if i rely on javascript only within evaluate:

(.stringify js/JSON (.-localStorage js/window))
i get no errors.

darwin19:03:42

yes, I’m using puppeteer in several projects to run cljs tests

darwin19:03:01

show us more code, how you call page.evaluate, etc.

dangercoder19:03:52

(defn check-for-error [page]
  (.evaluate page (fn [_]
                    (let [selector "myselector"
                          element (.querySelector js/document selector)]
                      (js/console.info element)
                      (when element
                        (.-innerHTML element)))) 1))
@U08E3BBST awesome! here is the function that is failing.

darwin19:03:14

and do you really have cljs libraries present in the page’s js context? try to eval “typeof cljs” (js code as string)

darwin19:03:40

the code you wrote compiles to "function (_){\nvar selector = \"myselector\";\nvar element = document.querySelector(selector);\(element);\n\nif(cljs.core.truth_(element)){\nreturn element.innerHTML();\n} else {\nreturn null;\n}\n}", which needs cljs runtime present

dangercoder19:03:15

tried to eval it, got: Error: Evaluation failed: ReferenceError: cljs is not defined   `at puppeteer_evaluation_script__:2:1`

darwin19:03:24

you need cljs.core in the page, it seems you have not imported any cljs code there

dangercoder19:03:40

Thanks @U08E3BBST for the assistance. I will check out how to do it 🙂, im quite new to the puppeteer api.

dangercoder19:03:14

looks like page.addScriptTag is what im looking for

darwin19:03:50

yes, you need to import clojurescript stuff somehow

darwin19:03:14

I do it standard way via html and instruct puppeteer to open that url

dangercoder20:03:22

I don't think I can do it your way since I am running puppeteer against a non-test-environment website

darwin20:03:58

btw. in your evaluate code snippet you don’t seem to rely on cljs that much, why not writing it in plain js?

dangercoder20:03:30

yeah that sounds like a great idea I had the same thought. so I would just js/eval a javascript string?

darwin20:03:40

your trouble is that the emitted code contains a call to “cljs.core.truth_” which is not essential to what you are trying to do there

dangercoder20:03:59

I see, I wrote some vanilla js to solve the problem. 🙂