This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-16
Channels
- # announcements (7)
- # aws (9)
- # babashka (31)
- # beginners (28)
- # calva (14)
- # clj-kondo (29)
- # cljs-dev (23)
- # cljsrn (16)
- # clojure (21)
- # clojure-france (1)
- # clojure-nl (2)
- # clojure-spec (20)
- # clojure-sweden (4)
- # clojure-uk (6)
- # clojurescript (62)
- # community-development (5)
- # conjure (81)
- # cursive (14)
- # datomic (5)
- # defnpodcast (2)
- # docker (1)
- # figwheel-main (11)
- # fulcro (17)
- # graalvm (5)
- # jobs-discuss (5)
- # kaocha (1)
- # off-topic (54)
- # pathom (1)
- # pedestal (1)
- # quil (1)
- # re-frame (34)
- # shadow-cljs (34)
- # tools-deps (39)
- # uncomplicate (2)
that's nice and I actually thought about going this direction but I am not sure how it keeps everything paired up, since (vals testmap) and (keys testmap) might return them in different order
You are right to be concerned, but you are not relying on there being any particular order for the keys and vals. To be clear, if you made a map with :key1-20 and "val1-20", you don't need to know if :key5 comes first or :key8 comes first, all you need is for the iterator/seq to be consistent between two function calls. The return order can change tomorrow, but as long as the iterator returns values in some consistent way, I don't see a reason to worry about keys/vals being different.
@andrea.crotti for tracing, perhaps look at debux https://github.com/philoskim/debux
Is there some way, something like reader conditionals, to tell the compiler to produce node-specific code?
For example, I want to require crypto
if it’s nodejs, otherwise I want use js/crypto
.
I only found this https://stackoverflow.com/questions/47483193/how-to-define-target-env-in-compile-time-while-building-cljs, but maybe there is something more elegant.
This should work
(if (identical? *target* "nodejs") ... ...)
*target*
is replaced with current compile target and Closure will eliminate non reachable code then
I'm playing with hooks and porting over Dan Abramovs "use-interval" example: https://overreacted.io/making-setinterval-declarative-with-react-hooks/
As a hook newb, I'm now stuck figuring out why I'm getting this warning: > Warning: Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn't have a dependency array, or one of the dependencies changes on every render.
Here's my code: https://github.com/pesterhazy/cljs-scrap/blob/6fb1ddde715c293141af3639e1364555cfdd8dda/src/main/scrap/scrap.cljs#L12 (no react wrappers, it's a pure js port of the js example)
The effect sends me in a vicious rerender loop (hence the warning) but I can't seem to figure out why
Found a minimal repro: https://github.com/pesterhazy/cljs-scrap/blob/recoil/src/main/scrap/scrap.cljs#L37 - there must be something wrong with my re-implementation of use-interval :thinking_face:
working implementation here: https://github.com/donavon/use-interval/blob/master/src/index.js#L3
I have the following JS:
let ismdwn = 0
rpanrResize.addEventListener('mousedown', mD)
function mD(event) {
ismdwn = 1
document.body.addEventListener('mousemove', mV)
document.body.addEventListener('mouseup', end)
}
function mV(event) {
if (ismdwn === 1) {
pan1.style.width = event.clientX * 2 + \"px\"
} else {
end
}
}
const end = (e) => {
ismdwn = 0
document.body.removeEventListener('mouseup', end)
rpanrResize.removeEventListener('mousemove', mV)
}
And I'm trying to make a react component out of it (using rum). But I'm wondering how does someone normally encapsulates all these event handlers?My only thought right now is that, maybe I can't avoid the global dom references, so I could use gensym to generate unique ids and in a did-mount on the component I could register the events
What would be the ClojureScript code for: pan1.style.width = event.clientX * 2 + "px"
I'm trying to build a rum component for the last snippet in this answer: https://stackoverflow.com/a/55189834/172272
hm, you probably don’t want to use event listeners / modifying the DOM directly with Rum
I’d probably use something like https://github.com/tomkp/react-split-pane
generally with React (which rum wraps), you want to track your UI state in the component and re-render based on changes to that state. not directly manipulate the DOM
yeah, let me whip up a quick React example that basically maps to the vanilla JS version
I think part of my confusion about re-rendering, is that, the html and css are global
here’s what I have so far: https://codesandbox.io/s/nameless-hooks-9ixbw?file=/src/App.js
this would be ideal but it doesn’t actually work, because you do in fact need to use global event listeners
Hum, ya, I guess because the drag can go beyond into the whole document. Unless it would be possible to like put an invisible thing that covers the whole page as part of the component, and register mouse event on that
But thanks for the example, I will study it. I guess I probably need to read a React tutorial, thought I could get away with only the Rum readme 😛
React/rum prefers to operate on the idea that you return the elements that should be rendered, and how they should be rendered, in a declarative fashion
so in my example, you pass in the current width to the Panel
component (which is just a dumb div underneath with some styling)
we can easily attach event listeners to elements inside our component like:
<div onMouseDown={() => console.log("down!")} />
the problem is that you need to attach the mouse move and mouse up to the document, since those events don’t actually happen to the div that’s acting as the resizer. they’re just global events, that we want to react to when the mouse has clicked down on the resizer
so I used some react-y ways to add those global event listeners, and remove them when the component unmounts
I think the latest version of rum provides the ability to use hooks, so it might be a straightforward translation
It does, but somehow when I look at them, I'm more confused compared to using the rum mix-ins which just let you define events on the component lifecycle