Fork me on GitHub
#hyperfiddle
<
2023-10-26
>
grounded_sage09:10:24

I'm missing something here but haven't figured it out yet. Trying to capture the mouse position on a component.

(defn mouse-position> [element]
  (m/observe
    (fn [!]
      (let [sample (fn [e]
                     (! {:x (.-clientX e) :y (.-clientY e)}))]
        (.addEventListener element "mousemove" sample )
        #(.removeEventListener element "mousemove" sample)))))

(defn mouse-position< [element]
  (->> (mouse-position> element)
    (e/throttle 16) ; RAF interval
    (m/reductions {} {:x 0 :y 0}) 
    (m/relieve (fn [acc evt] {:x (.-x evt) :y (.-y evt)}))
    (m/latest identity)))
Called liked this in a component.
(mouse-position< dom/node)

xificurC09:10:50

I think m/relieve is wrong, it should be (m/relieve {}). The caller needs to join the missionary flow with new, so the callsite should look like (new (mouse-position< dom/node))

Dustin Getz10:10:08

i believe the one in master is broken

grounded_sage10:10:57

The (new (mouse-position< dom/node)) and (m/relieve {}) did the trick. Though I'm not getting my crosshair rendering anymore. So have to figure out why that it.

Dustin Getz17:10:07

also i dont understand why we are throttling, I know i have seen that pattern in the electric repo somewhere but maybe it is an old workaround

grounded_sage17:10:32

It didn't really seem to do the trick so I am not throttling now.

grounded_sage21:10:58

Oh and I got it from @U0ETXRFEW searching this channel

pez21:10:09

I don’t really understand the role of the throttle either. Just that things didn’t work without it. 😃

pez21:10:38

And right now I don’t even remember if the latest code for our mouse crosshair has the throttle still in place.

joshcho23:10:20

Since people here may be interested; how do you solve the yak-shaving problem? Essentially yak-shaving is working (too much) on the tools to solve the problem. I tend to err too much on this side, but often end up finding powerful technologies to justify the search/work.

hiredman23:10:23

I sigh a lot instead of working on tools, think about https://codahale.com//work-is-work/, go get a coke

👍 1
henrik07:10:00

The economics are different when working in a team vs. working by yourself. I’ve spent time on conveniences that I probably wouldn’t have bothered with if it only would impact me. But since they impact a certain number of other people, the gains increase. When Electric solves incremental compilation, it won’t just cut compilation times by <insert number here>, it will cut compilation times by <insert number here> times <number of Electric users>.

🔥 1
henrik07:10:55

If you’re Google, you could probably measure it on the electricity bill.

😂 1
Dustin Getz12:10:45

"do things that don't scale"

Dustin Getz12:10:19

honestly the motivation to ship is to watch retards get rich on things like remix_web while we barely survive for years. As well as learned humility from multi-year efforts to shave a yak that failed in the end because "built wrong thing" 'idea was wrong" "didn't work in practice" etc.

Dustin Getz12:10:28

"Time is the denominator"

henrik12:10:32

Electric, at least, is none of those things

🔥 1
joshcho13:10:29

I think also sth like “have class” is a thing. At least it’s a dimension (other than money)