Fork me on GitHub
#clojurescript
<
2018-10-09
>
romdoq08:10:09

Is there a sensible way to compile to a javascript web-module, such that a particular cljs namespace can be imported into an existing web app?

thheller08:10:30

@mel.collins that depends on the packaging mechanism you use in the existing web app

romdoq08:10:20

very good point. It's a node site, so uses npm/yarn

thheller08:10:57

that doesn't mean much these days. does it use webpack?

romdoq08:10:07

I've actually managed to get the thing imported in the site, but it needs to be accessed via hello.hello_world.core.hithere(), whereas I'd prefer something just like hello.hithere()

romdoq08:10:41

I guess my question is more about how to build an npm package targeted at the browser-side

romdoq08:10:11

but the site does use webpack, yeah

romdoq08:10:07

thanks @thheller, I'll take a dive into shadow-cljs and see where it takes me

romdoq09:10:18

apparently shadow-cljs it takes me to Successville! 😄 Thanks again!

JH13:10:41

How would I write window.navigator.msSaveBlob(blob, filename+'.pdf') in cljs with js interop?

lukas.rychtecky13:10:04

(-> js/window .-navigator (.msSaveBlob blob (str filename ".pdf")))

SriniKausik14:10:13

@U6HHQ05GB that works - thank you 👍:skin-tone-2:

rpkarlsson13:10:40

@jacob.haag I think (js/navigator.msSaveBlob blob (str filename ".pdf")) should work.

moo15:10:01

Can anyone recommend a clojurescript webapp dev house?

👀 4
moo15:10:46

(for a small to medium sized dashboardy project)

lilactown18:10:19

:thinking_face: is there a way to use with-redefs with a function that returns a go channel?

dnolen18:10:59

I would avoid any kind of binding/rebinding in a go block

polymeris18:10:02

I am doing this and it seems to be working... what should I watch out for? https://github.com/polymeris/cljs-aws/blob/master/test/cljs_aws/dynamodb_test.cljs#L11

polymeris18:10:53

(that macro expands to (with-redefs ...)

lilactown18:10:05

😞 thought not. thanks!

lilactown18:10:40

so it seems then that if I want to test any async function, I need to pass in any functions I would want to stub as arguments

dnolen18:10:43

cljs.test has workarounds for some aspects of this problem

dnolen18:10:19

I think you can rebind in the fixture?

dnolen18:10:27

if not it’s not hard to write your own macro or whatever to do this

dnolen18:10:35

it’s less problematic with cljs.test because tests run in order

dnolen18:10:39

they won’t run in parallel

ska20:10:01

I have a question regarding string escapes with backslashes, replace and a difference to CLJ:

ska20:10:17

I need two different calls in CLJ and CLJS to get the same result and would appreciate if someone could explain that to me.

(s/replace "1 abc" #"(\d)" "$1\\\\.") ;; CLJ
(s/replace "1 abc" #"(\d)" "$1\\.") ;; CLJS
;; to get:
"1\\. abc"
Is there a supposed way to do this correctly?

Jimmy Miller20:10:13

Clojurescript uses javascript’s regexes while Clojure uses Java’s. This is a difference between the two. https://clojurescript.org/about/differences#_other_functions

ska20:10:48

with s being clojure.string

ska20:10:42

For the record: I can work around the differences between CLJ and CLJS by invoking s/replace with a fn as last argument. There the escaping works as expected. Still, I find this subtle and surprising.

lloydshark21:10:01

@lilactown For me I have used

set!
for replacing a function that is being called amongst my async code for testing purposes. You just need to manage the lifecycle yourself (if it even matters for your particular tests).

lilactown21:10:36

interesting. that might be cleaner then relying on with-redefs' magic

darwin21:10:49

@ska this is by design, clojure uses strings from host platform and regex behaviour is different between java and js

darwin21:10:15

but now when I think about it, your case seems to be different, because the bug seems to be in escaping of strings, not regex stuff

mfikes21:10:50

I’m struggling to understand Clojure’s behavior in the s/replace example. Reading the source…

mfikes21:10:48

Ahh, this appears to be explained in Matcher.replaceAll JavaDoc where it describes the special handling of backslash characters.

mfikes21:10:36

ClojureScript could theoretically behave like Clojure, also introducing re-quote-replacement, but this would either be deemed a breaking change or a bug in ClojureScript.

darwin22:10:29

if anything needs fixing, the bug is in Clojure, IMO 🙂

mfikes22:10:10

Yeah, Clojure is adopting Java’s behavior, which “interprets” backslash characters in the replacement string.

👌 4
deliciousowl22:10:12

soon, cljs will conquer the world

mfikes22:10:24

In Clojure’s defense, it lets you opt out via re-quote-replacement

mfikes22:10:47

But it is an all-or-none thing

mfikes22:10:54

(You can fix the backslashes but then the dollar signs are neutered as well.)

darwin22:10:00

@coinedtalk next Clojure dialect will be branched from ClojureScript behaviour, I'd like to see ClojureScriptReason, which would compile down to Ocaml/Reason and have normally behaving backslashes 😉

mfikes22:10:10

If we add enough type inference to ClojureScript it will be equivalent to Reason 😀

darwin22:10:32

sounds reasonable 😛

😂 4
mfikes22:10:05

Or even clojureabe

😂 8
andy.fingerhut22:10:53

I mean, you could write a different version of ClojureScript or Clojure/Java replace that works however you want, but a regex library is almost certainly not something many people want to write or maintain.

andy.fingerhut22:10:19

If they work differently in Java vs. JavaScript, the library authors had some reasons for doing so (maybe not good ones, but reasons).

andy.fingerhut22:10:31

In Clojure/Java you could I believe use re-quote-replacement on part of a replacement string only, and concatenate it with other strings, but I have no idea whether that makes it easier to be more similar between Clojure vs. ClojureScript. The function approach sounds like a more straightforward way to reach that goal.

andy.fingerhut22:10:02

If you delve further into regex capabilities of one or the other platforms, I will bet you $5 you will find other even more subtle differences.

mfikes22:10:36

@ska You might get closer to sanity by passing

(str "$1" (re-quote-replacement "\\."))
as your replacement string. You’d define re-quote-replacement as identity in ClojureScript. Not saying to actually do that, but it may aid in understanding.

mfikes22:10:32

(Or what Andy just said 😀)

andy.fingerhut22:10:48

e.g. I don't know if JavaScript regexes support Unicode character sets, but I know that the definition of which characters are in those sets changes across Unicode releases, so across different JDK versions, and I would guess across JavaScript releases, too. The more basic your use of regex features, the more likely they are to work identically across implementations. (Is it a bug in JavaScript if it works differently than Perl? :)

idiomancy23:10:55

do I need to set up my project.clj any special way to make sure it pulls in deps.edn?

idiomancy23:10:06

do projects that use deps.edn even have a project.clj?

idiomancy23:10:22

oh god... I just want to use my fork

darwin23:10:49

deps.edn and project.clj don't know each other, unless you marry them via some other tool

darwin23:10:15

are you familiar with lein'

idiomancy23:10:58

I certainly wouldn't call myself an expert with the tooling, but I'm familiar

idiomancy23:10:49

What do you suppose the shortest path to depending on a forked rep would be?

darwin23:10:29

if your project uses lein, then go with checkout dependencies, if it does not use anything, then start with deps.edn

idiomancy23:10:01

it uses lein. I have a complex aggregation of project.clj witchcraft supporting my autoreloading figwheel setup

idiomancy23:10:16

I only 60% know what each piece does.

darwin23:10:12

or alternatively, if you just need a quick dirty patch on your local machine only, then you can patch your forked lib and install it locally with same version as official release (so your code would pick it up instead)

idiomancy23:10:29

nah, I need this to work on the browser

darwin23:10:56

not sure if I understand, what do you mean "on browser" ?

idiomancy23:10:46

err.. well, actually you're right I guess I wasn't considering the fact that even if I patch it locally, I can compile the JS and deploy it anywhere

idiomancy23:10:31

I'm too used to thinking about servers. Well, a checkout it is, I suppose..

darwin23:10:05

sure, clone the repo, make your changes, look into their project files, force version, and then build+install it locally

darwin23:10:46

then your code will see it instead of the official released version

idiomancy23:10:57

okay, cool. gotcha.

darwin23:10:04

or better bump version to your own and change your project to depend on your specific custom version

idiomancy23:10:06

say, thanks! That was very helpful!

👍 4