Is extra within a component meant for private state? Is there a way (maybe hacky?) to access a component's extra state from another component?
I want to show the modifiers state from https://github.com/phronmophobic/clobber/blob/913ab1206dbe02a4c019d74ade9f24a24bdbbb86/src/com/phronemophobic/clobber/modes/clojure/ui.clj#L1450 in a different component, something like this (but this doesn't work)
(component/defui wrapper [{:keys [editor] :as args}]
(let [modifiers (get extra ::cljui/modifiers)
ed-ui (cljui/code-editor
{:editor editor
:$editor $editor})]
(ui/vertical-layout
(ui/bordered ed-ui)
(ui/bordered
(ui/padding 10
(ui/label (pr-str modifiers)))))))
I'm guessing this is intentionally hidden and if the state is to be shared it should be brought out into a higher level component, right? (confirmed that this does indeed work)extra is meant for private and incidental state. If a component uses state directly from extra, that means it is not meant to be part of the public API (ie. private). You can still access private state though. I haven't tried it, but this should work:
(component/defui wrapper [{:keys [editor] :as args}]
(let [code-editor-extra (get extra ::code-editor-extra)
modifiers (get code-editor-extra ::cljui/modifiers)
ed-ui (cljui/code-editor
{:editor editor
:$editor $editor
:extra code-editor-extra})]
(ui/vertical-layout
(ui/bordered ed-ui)
(ui/bordered
(ui/padding 10
(ui/label (pr-str modifiers)))))))There's definitely more room for simplification in that part of the code.
hmmm I'm finding that this works only if within the code-editor source, I also pass extra to "propagate" it
(defui code-editor [{:keys [editor
^:membrane.component/contextual
focus]
:as this}]
...
(clojure-keymap {:bindings clojure-keytree
...
:extra extra})
I think it would work if the private state were actually in the code-editor component?oh, right
that probably just means the extra that clojure-keymap isn't directly in the extra passed to code editor
I think all of that code probably needs to get updated to be simplified, so it might just be easier to add modifiers as an explicit arg to clojure-keymap and code-editor for now.