New idea for workshop doc: micro tags for smaller, easier-to-digest evolutionary steps: https://github.com/kennytilton/web-mx-workshop/wiki/The-Evolution-of-a-Web-MX-Inspector#tag-retarget-refactor I am thinking tags so far have thrown in too much at one time for comfortable learning.
I forgot this would happen. I used the new targeted opt-cmd-click feature to inspect directly a steadily changing speedometer widget and -- Doh! -- the information in the inspector is changing, too.
(defn- mxi-widget-inspector []
(cF+ [:watch (fn [_ _ handler-fn _ _]
(.addEventListener js/document "click" handler-fn))]
(fn [raw-evt]
(let [click-evt (wmx/jso-select-keys raw-evt
[:target :metaKey :altKey :shiftKey :ctrlKey])]
(when (= (dissoc click-evt :target)
{:metaKey true, :altKey true, :shiftKey false, :ctrlKey false})
(.stopPropagation raw-evt)
(mset! me :target ;; 'me' is the inspector, the owner of the property this formula controls
(wmx/dom-tag (:target click-evt))))))))
Fun fun fun. 🙂 But now I have to show the parent in the inspector, and try applying without-c-dependency because a constantly shifting inspector could be a tad frustrating. I guess it could be an option. Could be a good next microtag."I forgot this would happen"
Nope! To my surprise, for the most part I properly used a backdoor to get a model property value: (:my-property-name @md). ie, an MX model is just a map, and values or props live write in the key-value pair. (Original Cells worked differently, with the cell data structure itself being the value of a key-value pair.)
So why does the inspector update? Because:
1. I did not bypass cells when reading the children of a widget, I used (mget md :kids) ; and
2. in HTML-land, the text of a SPAN is a child of a SPAN, and I mirrored that in Web/MX by taking (span "Hi, Mom") and expanding that into sth like:
(span :kids (cFkids "Hi, Mom"))
Actually, here is the code, roughly:
(span {}
{:name :speedometer
:mph (cI 42)
:display (cF (str (mget me :mph) " mph"))}
(mget me :display))
...and expanded:
(span
:name :speedometer
:mph (cI 42)
:display (cF (str (mget me :mph) " mph"))
:kids (cF (mget me :display))
Now I could just change (mget md :kids) to (:kids @md), but in the spirit of moving forward I have belatedly exposed without-c-dependency in t.matrix.api and will use that.
For the curious:
(defmacro without-c-dependency [& body]
`(binding [*depender* nil]
~@body))
Too easy? 🙂