So, bless Helix, this works
(mkx rn/Button
:name :counter42
:counter (cI 3)
title (cF (str "Counter = " (mget me :counter)))
:disabled (cF (not (mget (mxu! me :counting?) :value)))
:jsx {:title (mget me :title)
:disabled (mget me :disabled)
:color "black"
:onPress #(mswap! me :counter inc)})
That is a reactive matrix object with reactive properties :title, :counter, and :disabled.
Not shown is the rn/Switch named :counting? that disables :counter42.
:jsx is a cruel pun on RN. The associated map gets fed to the Helix $ macro in the props position to create the element.
Works great, but the dream would be:
:jsx (with-props [:title :disabled]
:color "black"
:onPress #(mswap! me :counter inc))
I need the macro so I can emit code that captures me (akin to self or this), an anaphor established by another Matrix macro CF that emits the code to build the element.
Unfortunately with-props conflicts with the $ macro's handling of the attributes map (as nicely documented! Along with the :& workaround!!):
:jsx {:& (with-props :title :disabled)
:color "black"
:onPress #(mswap! me :counter inc))}
Not shabby at all, esp. since the :& was tolerated in the first position. 🙂
All of this an incredibly long way of asking if I could have made the dream solution ^^^ work. Maybe a cleverly positioned clj->js? I did try that, but perhaps I had it at the wrong stage of macro expansion.
perhaps pass the whole :jsx map into :&?
I'm v happy to hear that the documentation was clear to you about that btw. I think that's one of the biggest confusions people have onboarding to helix (static props + using :&)
"pass the whole :jsx map into :&?"?! Diabolical. I like it. brb...
Heh-heh, it works:
:jsx {:& (with-props [:title :disabled]
:color "cyan"
:onPress #(when (mget (mxu! me :counting?) :value)
(mswap! me :counter inc)))}
It's a little busy, tho. Perhaps some more macrology can obviate the need for :jsx.
Thanks for the idea. 🙏