Fork me on GitHub

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.


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


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


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


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


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…


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


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)


how to add externs to all :cljsbuild builds?


@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 =)…


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?


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.


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


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


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


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


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


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


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


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


looks like page.addScriptTag is what im looking for


yes, you need to import clojurescript stuff somehow


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


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


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


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


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


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