This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-09
Channels
- # 100-days-of-code (6)
- # announcements (4)
- # atlanta-clojurians (1)
- # aws (1)
- # beginners (65)
- # boot (21)
- # cider (9)
- # cljsrn (3)
- # clojure (186)
- # clojure-android (4)
- # clojure-conj (1)
- # clojure-dev (12)
- # clojure-germany (3)
- # clojure-italy (8)
- # clojure-nl (1)
- # clojure-russia (32)
- # clojure-spec (19)
- # clojure-uk (41)
- # clojurescript (83)
- # core-async (5)
- # cursive (18)
- # datomic (15)
- # emacs (5)
- # events (4)
- # fulcro (7)
- # hyperfiddle (4)
- # leiningen (4)
- # liberator (1)
- # off-topic (65)
- # overtone (4)
- # pedestal (5)
- # perun (1)
- # planck (3)
- # re-frame (1)
- # reagent (3)
- # rum (5)
- # shadow-cljs (8)
- # spacemacs (19)
- # testing (3)
- # tools-deps (4)
- # yada (6)
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?
@mel.collins that depends on the packaging mechanism you use in the existing web app
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()
I guess my question is more about how to build an npm package targeted at the browser-side
you could try https://shadow-cljs.github.io/docs/UsersGuide.html#target-npm-module which works fine with webpack
How would I write window.navigator.msSaveBlob(blob, filename+'.pdf')
in cljs with js interop?
(-> js/window .-navigator (.msSaveBlob blob (str filename ".pdf")))
@U6HHQ05GB that works - thank you 👍:skin-tone-2:
You welcome!
@jacob.haag I think (js/navigator.msSaveBlob blob (str filename ".pdf"))
should work.
:thinking_face: is there a way to use with-redefs
with a function that returns a go
channel?
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
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
I have a question regarding string escapes with backslashes, replace and a difference to CLJ:
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?Clojurescript uses javascript’s regexes while Clojure uses Java’s. This is a difference between the two. https://clojurescript.org/about/differences#_other_functions
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.
@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).@ska this is by design, clojure uses strings from host platform and regex behaviour is different between java and js
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
I’m struggling to understand Clojure’s behavior in the s/replace
example. Reading the source…
Ahh, this appears to be explained in Matcher.replaceAll
JavaDoc where it describes the special handling of backslash characters.
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.
Yeah, Clojure is adopting Java’s behavior, which “interprets” backslash characters in the replacement string.
soon, cljs will conquer the world
@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 😉
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.
If they work differently in Java vs. JavaScript, the library authors had some reasons for doing so (maybe not good ones, but reasons).
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.
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.
@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.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? :)
do I need to set up my project.clj any special way to make sure it pulls in deps.edn
?
deps.edn
and project.clj
don't know each other, unless you marry them via some other tool
if your project uses lein, then go with checkout dependencies, if it does not use anything, then start with deps.edn
https://github.com/technomancy/leiningen/blob/master/doc/TUTORIAL.md#checkout-dependencies
it uses lein. I have a complex aggregation of project.clj witchcraft supporting my autoreloading figwheel setup
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)
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
sure, clone the repo, make your changes, look into their project files, force version, and then build+install it locally