cljfx

Dave 2024-05-09T19:56:28.124139Z

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

vlaaad 2024-05-10T08:46:22.760109Z

I saw your post in #beginners and thought it’s not cljfx related πŸ™‚

vlaaad 2024-05-10T08:47:45.596319Z

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

vlaaad 2024-05-10T08:48:24.585939Z

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

vlaaad 2024-05-10T08:48:28.497349Z

Β―\(ツ)/Β―

vlaaad 2024-05-10T08:48:59.450369Z

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

vlaaad 2024-05-10T08:51:20.782359Z

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
vlaaad 2024-05-10T08:51:57.267749Z

so map event handler looks as simple as:

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

Dave 2024-05-10T18:10:41.504559Z

Thanks for the reply @vlaaad, 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).