hyperfiddle

2025-05-09T15:20:46.555269Z

what's the v3 solution for a button click handler that needs to call an e/fn? i'm currently using the token antipattern, but wondering if there's a better solution. use case is a single click event that should trigger something on the server

henrik 2025-05-12T15:22:07.374929Z

This is great. Whatโ€™s arity-1 on spend? Does it just want a value that represents failure in the app domain logic?

xificurC 2025-05-12T15:23:54.364029Z

yes, this is a common pattern, but it's really just a data slot

๐Ÿ‘ 1
xificurC 2025-05-12T15:27:38.313269Z

re token composition, here's a fun one. Makes a DOM node draggable on left click. TokenNoFail is a token from token-zoo namespace that doesn't have the data slot. Notice how the token from mousedown models the lifetime of the drag until mouseup spends it. Something that wasn't possible with v2's dom/on whereas here it's trivial and intuitive

henrik 2025-05-12T15:31:04.759979Z

Nice! But wonโ€™t you be spamming out a new t for every change in mouse-x , causing rebinding of the "mouseup" event continously?

henrik 2025-05-12T15:32:28.850679Z

No, nevermind โ€œdownโ€ is a single point in time.

xificurC 2025-05-12T15:35:23.703399Z

even if it was possible to mousedown N times the token doesn't change, if you have one you have it until you spend it. I.e. changes to the token's input value won't create a new token when you already have one

๐Ÿ‘ 2
xificurC 2025-05-09T15:32:30.996529Z

tokens are not an anti-pattern, we built them to address this specific scenario

๐Ÿ™ 1
Dustin Getz (Hyperfiddle) 2025-05-09T15:57:09.501069Z

tokens give you transaction monitoring, i.e., pending and retry states

Dustin Getz (Hyperfiddle) 2025-05-09T15:59:44.789969Z

if your server effect doesnt require pending and retry states, you can use

(let [counter (dom/button (dom/On "click" (partial (fn [!n e] (swap! !n inc)) (atom 0)) 0))]
  (e/server (println counter))
let can be when-some if you want to start nil

๐Ÿ™ 3