@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?yes. in your example you can do (swap! isclicked not)
user=> (def clicked? (atom false))
#'user/clicked?
user=> (swap! clicked? not)
true
user=> @clicked?
true
user=>
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
ohhhhh that makes sense, thanks so much @dpsutton time and help
for sure!
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?
Hello, how to deal with tag object such as data and time in cljs, sent from clj? Thanks.
got an example?
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\"]}"
One way is using tick library with time-literals
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.
but you can't send an arbitrary java object (or a string representation of one) over to the browser
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
Thank you. Then to deal with data and time, I should convert these into string representation before transmit between server and client.
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
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"]
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
never mind, its' called on-mouse-move
!
haha you had me doubting myself, was just pulling up a project to try it out
glad you figured it out !
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.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?https://soundcloud.com/user-959992602/followers we need more clojurescript podcast followers. awesome content
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)] ...)
?
https://google.github.io/closure-library/api/goog.dom.html has a helpful findElement
function
Just in case - if you're using React, use refs.
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 thatput 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
^ that. Or just react/createRef
if you prefer React API to atoms.
First and foremost, read the documentation on refs. There might be some surprises that aren't fun to debug.
and its sensitive to inline functions that are recreated on every render versus defined functions
thanks, I'll dig into that!
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
there seems to be a jira issue somewhat related to this: https://clojure.atlassian.net/browse/CLJS-2982
not related to that jira issue i don't believe. its just wrong
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->hex
function. Any suggestions for a simple function to convert a js/Uint8Array into a string of hexidecimal characters?
i'm suprised the compilation is failing unless you have warnings set to throw errors
you could just grab the source with attribution
https://github.com/cloojure/tupelo/blob/master/src/cljc/tupelo/misc.cljc#L127-L147
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).
Thanks for your help and quick response. This is a great channel!!!
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)
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
based on these warnings i wouldn't use this library
Does heavy use of core.async have a big affect on the output during advanced mode?