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
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
tokens are not an anti-pattern, we built them to address this specific scenario
tokens give you transaction monitoring, i.e., pending and retry states
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