Fork me on GitHub
#cljfx
<
2024-05-09
>
Dave19:05:28

Hi Everyone, I posted this question in the beginners channel, but didn't get much a of a response. I am curious to know how you all look up definitions and call trees when using publish/subscribe or events in CLJFX: Context: • I am using the cljfx library for a few of my projects, and I have a basic question about finding callers and callees in Clojure code using events. I don't think my question is cljfx specific, though it has examples from it. Main question: • Is there a simple way to identify where this input parameters current-dir are defined/set/modified? ◦ I usually use "Go to definition" in IntelliJ or Emacs, however decouling the code with event messages seems to completely break this flow. Example: I am swapping the state atom with the current directory that the user has selected from a GUI here:

(defmethod event-handler ::display-files [{:keys [current-dir]}]
  (swap! *state assoc :files (util/list-clojure-files current-dir)))
Here is where I define the component
(defn file-list-view [{:keys [files selection current-dir]}]
  {:fx/type fx.ext.list-view/with-selection-props
   :props   {:selection-mode            :multiple
             :selected-items            selection
             :on-selected-items-changed {:event/type ::events/update-selected-files-svg}}
   :desc    {:fx/type      :list-view
             :cell-factory {:fx/cell-type :list-cell
                            :describe     (fn [item]
                                            {:text (util/str->relative-path item current-dir)})}
             :items        files}})
When I do a "Go to definition" it is able to do a basic search for the keyword here, however, it is not able to tell me in any simple way that the atom is set in the ::display-files handler. Screenshot attached to show IntelliJ's go to definition search. Here is the repo if anyone cares to take a look: https://github.com/aeonik/graph/blob/main/src/aeonik/gui/main.clj

vlaaad08:05:22

I saw your post in #C053AK3F9 and thought it’s not cljfx related 🙂

vlaaad08:05:45

When I read it, it looked to me like a general code navigation question that involves keywords

vlaaad08:05:24

i.e., if you want to know who uses something, and the use is driven by keywords, you have to search for keyword use

vlaaad08:05:28

¯\(ツ)

vlaaad08:05:59

Btw, in my cljfx projects I stopped using keywords for event identifiers

vlaaad08:05:20

What I do now is I use vars, and event maps look like this:

:on-key-pressed {:fn #'do-stuff}
e.g.: https://github.com/cljfx/dev/blob/main/src/cljfx/dev/ui.clj#L116

🙌 1
vlaaad08:05:57

so map event handler looks as simple as:

:fx.opt/map-event-handler #(swap! state (:fn %) %)

Dave18:05:41

Thanks for the reply @U47G49KHQ, I like this a lot. I will refactor my code. I guess it's the price we pay for proper decoupling and dynamic code. I will think of a solution to this, and get a fix out to the community as time and skill permits (I estimate about 7 years).