hyperfiddle 2025-05-09

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

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

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

๐Ÿ‘ 1

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

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

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

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

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