cljfx

Jeremy 2024-10-21T00:09:20.356729Z

for repl driven workflow, can a renderer be created for a subnode of the ui tree? currently, each (renderer) re-renders the whole window, but what if my app is large and i simply want to render a subsection?

vlaaad 2024-10-21T08:37:46.745519Z

You can do parts of UI tree in cljfx, e.g.:

(require '[cljfx.api :as fx])

(defn- root-view [{:keys [state swap-state]}]
  {:fx/type :text-field
   :text (:my-app state)
   :on-text-changed #(swap-state assoc :my-app %)})

(let [cljfx-managed-text-field (fx/instance
                                 (fx/create-component
                                   {:fx/type fx/ext-state
                                    :initial-state {:my-app "state"}
                                    :desc {:fx/type root-view}}))]
  (fx/on-fx-thread
    (doto (javafx.stage.Stage.)
      (.setScene (javafx.scene.Scene. cljfx-managed-text-field))
      (.show))))

👍 1
vlaaad 2024-10-21T08:38:36.125429Z

this is using ext-state, which sort of re-implements the renderer abstraction, but within the cljfx tree

vlaaad 2024-10-21T08:40:51.784379Z

you can do it with renderer too, but that’s going to be more involved, because you’ll need to invert the control a bit: you’ll need to pass a parent Node to the renderer, and then make a custom lifecycle that will put the root node into that parent

Jeremy 2024-10-21T08:46:11.997939Z

Thank you very much. It'll take a while for me to grasp as I don't know javafx 😅 . Just curious tho... if I put whole state in an atom then swap state, would cljfx rerender the treenodes that use that atom, or only the ones that depended on the part changed?

vlaaad 2024-10-21T08:48:41.446249Z

depends on what you mean by “rerender”. Cljfx will call all clojure view functions if their arguments change. The JavaFX nodes though will only be touched if their props that control them change

👍 1
vlaaad 2024-10-21T08:51:23.980809Z

I’d say don’t worry about it too early, I only run into performance issues when I was trying to display too many JavaFX nodes on the screen (e.g. 20 pages of ui inputs) and the source of the performance issues was always JavaFX not being able to render that many nodes at the same time.

Jeremy 2024-10-21T08:53:56.017109Z

I see, it shouldn't be expensive then. I do, however, wonder about having lots of nodes: supposed I had 8 table views with 300 rows each, a section for each tableview updates several times a second, in addition to several graphs, timers, etc. is it ok to be swapping global state for each update , or is it possible to have local state management for each table for performance reasons

vlaaad 2024-10-21T08:58:09.908979Z

tables also should be generally more performant than other javafx nodes because they are virtualized, i.e. they show actual Nodes only for visible part of the table

vlaaad 2024-10-21T09:00:10.425999Z

I’d say making it easier for you to implement and reason about would be a more important consideration than potential performance issues when it comes to selecting a single vs multiple state atoms

Jeremy 2024-10-21T09:00:45.693319Z

Ohk, great to hear. I was thinking I'd have to implement some kinda infinite list if the table wasn't performant (5-6 updates per sec)

Jeremy 2024-10-21T09:01:42.259729Z

Yh, the global state is much more easier to reason about. only concern was in a complex tree, if it would still offer decent performance

Jeremy 2024-10-21T09:01:55.176239Z

Thanks a lot @vlaaad

vlaaad 2024-10-21T09:02:03.630089Z

my pleasure 🙂