clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
fsd 2020-12-11T00:01:34.247900Z

@dpsutton thanks for your reply Ah I see, in Javascript I can just

let isclicked = false
false
isclicked = !isclicked
true
isclicked
true
isclicked = !isclicked
false
isclicked
false
Is there anyway I can change the value of a boolean variable to the opposite of its value like how I did it in JavaScript?

dpsutton 2020-12-11T00:13:18.248200Z

yes. in your example you can do (swap! isclicked not)

dpsutton 2020-12-11T00:14:18.248400Z

user=> (def clicked? (atom false))
#'user/clicked?
user=> (swap! clicked? not)
true
user=> @clicked?
true
user=>

dpsutton 2020-12-11T00:16:18.248600Z

if you just want to set the value of an atom irrespective of its current value then (reset! clicked? true) or (reset! clicked? (not @clicked?)) . note this one where you are setting its value based on the current value of the atom is precisely what (swap! clicked? not) is doing except its changing it atomically without race conditions

fsd 2020-12-11T00:21:48.248800Z

ohhhhh that makes sense, thanks so much @dpsutton time and help

dpsutton 2020-12-11T00:22:29.249100Z

for sure!

william 2020-12-11T02:08:04.250100Z

Hey, I'd like to do (.addEventListener js/document "mousemove" handler) but on a specific element. What's the idiomatic way of doing this in reagent? Using react refs?

2020-12-11T02:23:47.250800Z

Hello, how to deal with tag object such as data and time in cljs, sent from clj? Thanks.

dpsutton 2020-12-11T02:40:59.251Z

got an example?

2020-12-11T02:52:37.251500Z

For example, this edn from clojure to cljs, will not be read by cljs: (str {:A (java-time.local/local-date)}) ;; => "{:A #object[java.time.LocalDate 0x371f749c \"2020-12-11\"]}"

👍 1
2020-12-11T09:31:16.259Z

One way is using tick library with time-literals

dpsutton 2020-12-11T02:55:16.252300Z

correct because it hasn't been serialized in a way that it can be. "{:A #object[java.time.LocalDate 0x371f749c \"2020-12-11\"]}" isn't a readable string. So there's no chance of cljs handling it.

dpsutton 2020-12-11T02:56:57.252800Z

but you can't send an arbitrary java object (or a string representation of one) over to the browser

dpsutton 2020-12-11T03:02:30.254400Z

you can str it to get a nice format that you can reconstitute into a date on the cljs side. if you have timezone information you can use that to get a java.util.Date which has reproducibility between clj and cljs. You could also see how that is accomplished to achieve something similar

2020-12-11T03:04:03.254500Z

Thank you. Then to deal with data and time, I should convert these into string representation before transmit between server and client.

dpsutton 2020-12-11T03:06:00.254700Z

you're most probably using json or edn (or transit). all of these are string representations. that's kind of the name of the game

👍 1
Dane Filipczak 2020-12-11T03:09:01.254900Z

events are typically added via the attrs map passed in as the second element of a reagent component vector. e.g. [:div {:on-mouse-move my-handler} "div content"]

william 2020-12-11T03:25:31.255100Z

thanks @dane.email, but is that the case for on-move too? I get Unknown event handler property onMove if I try to use it as a map

william 2020-12-11T03:28:23.255400Z

never mind, its' called on-mouse-move!

Dane Filipczak 2020-12-11T03:29:25.255600Z

haha you had me doubting myself, was just pulling up a project to try it out

🙌 1
Dane Filipczak 2020-12-11T03:29:33.255800Z

glad you figured it out !

Charlie 2020-12-11T07:42:03.258700Z

Has anyone seen this error when using this unicode matching regex and compiling a prod build (optimizations advanced): (re-seq #"(?u)\p{L}\p{L}\p{L}+" input-string)

ERROR: JSC_UNTRANSPILABLE. Cannot convert ECMASCRIPT_2018 feature "RegExp unicode property escape" to targeted output language.
This code works in dev with figwheel.

william 2020-12-11T12:13:13.261300Z

In a reagent application, I have some code along the lines of:

(r/with-let [pointer (r/atom nil)
               handler #(let [rect (.. % -target getBoundingClientRect)]
                          (swap! pointer assoc
                                 :x (- (.-clientX %) (.-left rect))
                                 :y (- (.-clientY %) (.-top rect))))]
   widget
now, in the definition of rect, I'd like to take the bounding rect not of any element, but a specific sub-element of widget (otherwise, the target will change when I move to children). How could I do that in reagent?

2020-12-11T14:04:21.262100Z

https://soundcloud.com/user-959992602/followers we need more clojurescript podcast followers. awesome content

👍 1
william 2020-12-11T17:54:10.264Z

asking again, hopefully with a better question: how can I capture a piece of the dom (in my case an svg element) so that I can refer to it in something like (let [rect (.. MY_ELEMENT -target getBoundingClientRect)] ...) ?

dpsutton 2020-12-11T17:55:50.264100Z

https://google.github.io/closure-library/api/goog.dom.html has a helpful findElement function

p-himik 2020-12-11T18:25:42.264400Z

Just in case - if you're using React, use refs.

william 2020-12-11T18:57:12.264800Z

thanks! @dpsutton and @p-himik! I think I could have an XY problem right here so let's consider concretely:

(defn drawer-ui []
  (r/with-let [pointer (r/atom nil)
               handler #(let [rect (.. % -target getBoundingClientRect)]
                          (swap! pointer assoc
                                 :x (- (.-clientX %) (.-left rect))
                                 :y (- (.-clientY %) (.-top rect))))]
    [:div
     [:svg  {:on-mouse-move handler}
      ...]]))
The problem with this code is that when if I go over some of the children of the svg, the argument of handler is the child, and so I get the position relative to the child, while I want always the position in the whole svg. That's why I was asking about how to specify that

dpsutton 2020-12-11T18:59:09.265Z

put a ref function on the svg to reset an atom to the argument passed in to that function and use the value of that atom as the svg

p-himik 2020-12-11T18:59:32.265200Z

^ that. Or just react/createRef if you prefer React API to atoms.

p-himik 2020-12-11T18:59:58.265400Z

First and foremost, read the documentation on refs. There might be some surprises that aren't fun to debug.

dpsutton 2020-12-11T19:00:27.265600Z

and its sensitive to inline functions that are recreated on every render versus defined functions

william 2020-12-11T19:01:02.265800Z

thanks, I'll dig into that!

Dan Maltbie 2020-12-11T19:19:25.267800Z

Does anyone use Tupelo? I'm getting compile errors, like this one where it does seem to be wrong based on MapEntry documentation. ------ WARNING #1 - :fn-arity -------------------------------------------------- Resource: tupelo/core.cljc:1208:12 -------------------------------------------------------------------------------- 1205 | "Returns a clojure.lang.MapEntry constructed from the given key and val" 1206 | [key val] 1207 | #?(:clj (clojure.lang.MapEntry/create key val) 1208 | :cljs (cljs.core.MapEntry. key val))) ------------------^------------------------------------------------------------- Wrong number of args (2) passed to cljs.core.MapEntry

dpsutton 2020-12-11T19:22:40.267900Z

there seems to be a jira issue somewhat related to this: https://clojure.atlassian.net/browse/CLJS-2982

dpsutton 2020-12-11T19:26:23.268100Z

https://github.com/cloojure/tupelo/issues/17

dpsutton 2020-12-11T19:26:33.268400Z

not related to that jira issue i don't believe. its just wrong

Dan Maltbie 2020-12-11T19:35:21.268700Z

Yes I did notice the issues in Jira and Git around the use of MapEntry. Given that the Tupelo code is incorrect, I wonder if anyone is using it with Clojurescript. For me, the Tupelo compile is failing so it's not something I can fix in my code. I've tried the latest version as well as an older version. I just wanted to use their unsigned-byte->hexfunction. Any suggestions for a simple function to convert a js/Uint8Array into a string of hexidecimal characters?

dpsutton 2020-12-11T19:36:11.268900Z

i'm suprised the compilation is failing unless you have warnings set to throw errors

dpsutton 2020-12-11T19:38:59.269100Z

you could just grab the source with attribution

Dan Maltbie 2020-12-11T19:41:44.269600Z

Yes, you are correct that they are warnings. So I guess I should ignore them, though that seems like a bad practice. Cut and paste the code works for me since it is such a simple function (yeah I could have written it myself but Tupelo had already done it. sigh).

Dan Maltbie 2020-12-11T19:42:24.269800Z

Thanks for your help and quick response. This is a great channel!!!

dpsutton 2020-12-11T19:43:07.270Z

submit a patch. i believe you can just add a nil as the third argument. its a hash which can be nil signalling it needs to be computed (i think. going off memory)

Dan Maltbie 2020-12-11T19:47:48.270200Z

There was a second warning for an undeclared variable. I get nervous when my code has these warnings, let alone use a library that has them. While these two warnings are unrelated to the function I want to use, just seems like bad hygiene. ------ WARNING #2 - :undeclared-var -------------------------------------------- Resource: tupelo/core.cljc:1395:46 -------------------------------------------------------------------------------- 1392 | ;----------------------------------------------------------------------------- 1393 | (s/defn cum-vector-append :- s/Any ; #todo file bug report for CLJS 1394 | "Works inside of a with-cum-vector block to append a new vector value." 1395 | [value :- s/Any] (cum-val-set-it (append it value))) ; #todo copy td/cum-vector-swap-append kludge ----------------------------------------------------^--------------------------- Use of undeclared Var tupelo.core/it

dpsutton 2020-12-11T20:20:34.270400Z

based on these warnings i wouldn't use this library

grounded_sage 2020-12-11T21:17:40.271400Z

Does heavy use of core.async have a big affect on the output during advanced mode?