membrane

2025-06-18T15:17:06.273779Z

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)

phronmophobic 2025-06-18T16:25:22.829759Z

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)))))))

phronmophobic 2025-06-18T16:27:16.009859Z

There's definitely more room for simplification in that part of the code.

2025-06-18T18:00:26.062829Z

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?

phronmophobic 2025-06-18T18:01:24.718819Z

oh, right

phronmophobic 2025-06-18T18:01:55.929149Z

that probably just means the extra that clojure-keymap isn't directly in the extra passed to code editor

phronmophobic 2025-06-18T18:03:59.766439Z

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.

👍 1