Fork me on GitHub
#clojurescript
<
2020-02-04
>
David00:02:46

According to https://www.clojurescript.org/about/differences, cljs.spec and cljs.test are ports of their respective clojure namespaces.

David00:02:58

But I’ve got some cljs tests that require the clojure namspaces (not the cljs namespaces) and everything seems to run just fine.

David00:02:11

Is there a reason to prefer requiring cljs.spec and cljs.test in cljs tests or does it not really matter?

lilactown01:02:58

IMO it doesn’t really matter and I slightly prefer using clojure.*

lilactown01:02:06

but someone might disagree with me

lilactown01:02:41

since so many libs relied on clojure.core clojure.test etc., they implemented special handling of it in the compiler to rewrite clojure.* to cljs.*

Mario C.02:02:03

When using Cljsbuild with whitespace optimization this worked fine (.-addr (.-dataset e) where addr is a custom attribute. Then when setting optimization to advanced, I am getting nil. Any idea whats going on?

Mario C.02:02:54

For some odd reason I had to do (aget target-el "dataset" "addr")

p-himik08:02:13

If you're using shadow-cljs, you should be able to write (.-addr ^js (.-dataset ^js e)).

dnolen02:02:12

you should avoid property based access for data

dnolen02:02:56

goog.object/get is preferred, avoid aget - only for arrays

Alex Miller (Clojure team)02:02:23

you need a faq page to just point to that @dnolen :) (like https://clojure.org/guides/faq)

dnolen02:02:09

@mario.cordova.862 under advanced compilation property access will get renamed - that's why it doesn't work and should be avoided - (unless it's JS language properties or mature standard browser APIs)

👍 4
dnolen02:02:26

@david_clojurians we auto-alias clojure.foo -> cljs.foo - it helps with portability (i.e. cljc files) - it's intentional so feel free to use that feature as you see fit

dnolen02:02:50

@posobin you can trivially await promises w/ core.async - there's a patch to add support to core.async directly that I need to review once more

dnolen02:02:54

when the promise succeeds you can write that a core.async channel

dnolen03:02:39

core.async go blocks support async/await style syntax via the blocking operators <! >! etc.

Gleb Posobin15:02:47

But this way it is harder to deal with exceptions, no?

dnolen16:02:14

core.async has try/catch support just like async/await

dnolen16:02:42

but sure I expect the debug support for async/await to be pretty good since there's native support

dnolen16:02:50

IME though if you keep it simple, core.async is fine

Varenya05:02:25

is there a way to preprocess some files before compilation like converting svgs to hiccup components?

Roman Liutikov06:02:26

Yes, write a macro that reads a file, transforms SVG string into hiccup and expands into a component definition

Varenya06:02:47

yeah but that would require clojure primitives right like read a file

Roman Liutikov06:02:39

What's wrong with that?

Varenya06:02:26

hmm i am missing something here - the GCC won’t complain having a clojure primitive inside a clojure script file?

Roman Liutikov07:02:39

Macros are written in clj files, then when called in cljs files they are running at compile time. So you can read a file and transform contents at compile time and return hiccup which will be then compiled to js. I'd recommend to read more about macros in Clojure and ClojureScript.

Varenya07:02:43

yeah agreed thanks

orestis08:02:54

Yeah macros in ClojureScript are awesome. You have access to the entire Clojure ecosystem and the file system so you can go crazy :)

ShaneLester16:02:46

Has anyone had any luck getting a react async select to work in cljs? the callback/promise on loadOptions is throwin me off

ShaneLester17:02:25

I suppose the root of the issue is- anyone have any tips for interop that requires a promise / callback? Do I use a go block?

lilactown17:02:02

Callbacks and promises work in CLJS the same as JS

fricze17:02:33

Why can’t you use promise?

ShaneLester17:02:59

Perhaps I'm confused at a lower level of understanding. I'll look into using a promise directly

borkdude17:02:17

@shanelester55 Here's a script which uses promises directly: https://gist.github.com/yogthos/d9d2324016f62d151c9843bdac3c0f23#file-gallery-cljs. Maybe the example is useful to you.

ShaneLester17:02:11

Ahh thank you!

manutter5117:02:52

Boy, this is perplexing. I got an error f.call is not a function, stack trace indicates that it was happening in clj->js. Ok, I’ve got some values that I’m passing to clj->js, I’ll pprint them and see what the problem is. Now I’ve got f.call is not a function in pprint. Ok, printing doesn’t work, I wonder what the types are for those values? So I try (doseq [v values] (pprint {:type (type v)})). Now I’ve got f.call is not a function in Object.cljs$core$accumulating_seq_count.

manutter5117:02:14

What the heck have I got in my data that’s making everything blow up like that??

manutter5118:02:26

(Apparently that last one may be happening in a call to seq or count. Or both.)

thheller18:02:28

@manutter51 do you have a lazy seq in that data? that'll make things look weird sometimes

manutter5118:02:12

Ah, yes, I do, thanks for the clue, that wouldn’t have occurred to me

manutter5118:02:28

Oh word, I accidentally had the arguments to remove in the wrong order. What a wild way for that bug to show up!

manutter5118:02:57

Tks much @thheller I’d have been all afternoon on this one. 😉

Oliver George22:02:08

I'm looking for a good reference for how to evaluate CJLS expressions in the browser. Goal being allowing users to define functions (like defining a formula in an excel spreadsheet).

darwin22:02:13

that’s probably not very good reference for a beginner, but you can hopefully google more articles about self-hosting clojurescript compiler in your app

darwin22:02:27

ah, sorry, now looking at the link you posted below and it is about self-hosted compiler, so you already found it 🙂

jsa-aerial00:02:31

If you want a real example of this that is quite self contained, have a look at Saite https://github.com/jsa-aerial/saite. Specifically the analyzer.clj and compiler.cljs under the src/cljs/aerial/saite dir.

jsa-aerial00:02:06

Also, the codemirror.cljs shows how this is used interactively. If you want to see it all in action, grab the uberjar https://github.com/jsa-aerial/saite#uberjar and just start hacking!

Oliver George02:02:53

Thanks. Seems like i should consider an interpreter too. https://github.com/borkdude/sci looks interesting.

👍 4
Crispin02:02:13

I use sci in a number of projects. It's really great!

Oliver George22:02:26

I found this article dated 2015. Is it a good approach or have things moved on? https://yogthos.net/posts/2015-11-12-ClojureScript-Eval.html