This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-05-09
Channels
- # announcements (23)
- # babashka (7)
- # beginners (69)
- # biff (5)
- # calva (12)
- # cider (10)
- # cljfx (9)
- # clojure (60)
- # clojure-austin (1)
- # clojure-europe (14)
- # clojure-korea (2)
- # clojure-losangeles (2)
- # clojure-madison (1)
- # clojure-nl (1)
- # clojure-norway (23)
- # clojure-uk (7)
- # clojuredesign-podcast (16)
- # clojurescript (40)
- # datomic (8)
- # gratitude (4)
- # mount (3)
- # nrepl (2)
- # off-topic (38)
- # pathom (3)
- # releases (1)
- # ring (8)
- # shadow-cljs (7)
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.cljWhen I read it, it looked to me like a general code navigation question that involves keywords
i.e., if you want to know who uses something, and the use is driven by keywords, you have to search for keyword use
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#L116so map event handler looks as simple as:
:fx.opt/map-event-handler #(swap! state (:fn %) %)
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).