This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-19
Channels
- # announcements (15)
- # babashka (4)
- # beginners (55)
- # calva (92)
- # cider (70)
- # circleci (1)
- # clj-kondo (136)
- # cljdoc (2)
- # clojars (11)
- # clojure (48)
- # clojure-australia (1)
- # clojure-europe (30)
- # clojure-nl (3)
- # clojure-sweden (2)
- # clojure-uk (7)
- # clojurescript (40)
- # conjure (5)
- # core-async (11)
- # cursive (55)
- # data-science (1)
- # datomic (10)
- # degree9 (2)
- # development-containers (15)
- # events (1)
- # fulcro (14)
- # gratitude (13)
- # helix (5)
- # lsp (35)
- # malli (10)
- # meander (18)
- # off-topic (24)
- # pathom (13)
- # polylith (12)
- # practicalli (6)
- # re-frame (13)
- # reagent (33)
- # reitit (4)
- # remote-jobs (1)
- # shadow-cljs (13)
- # spacemacs (31)
- # specter (1)
- # stepwise (2)
- # tools-deps (19)
- # vim (1)
- # xtdb (7)
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.
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. 🙏