Fork me on GitHub
#cljfx
<
2021-01-16
>
raaon16:01:50

wondering if there is a way to get an event "behind" a re-render (ie, have it separate from the re-render batch of events) specifically i need to change my state (which will cause some nodes to delete and other to create/enter the scene) i want an event (call it ::re-focus that follows the re-render that will .requestFocus on the first node (per some css selector) in the scene graph (but this node doesn't exist until after the previous events have updated state and a re-render has occurred)

raaon17:01:44

ah i guess this is basic javafx ... (fx/run-later ...) does the job

raaon17:01:19

sharing code for posterity (or comment..):

(defmethod handle ::reset-focus
  [{:keys [^Scene scene-ref]}]
  (fx/run-later
    (some-> scene-ref
      (.lookup ".widget") ;; first widget in scene
      .requestFocus))
  [])

(defmethod handle ::switch-view
  [{:fx/keys [event]}])
  [[:state (assoc state ...)]
   ;; note: we reset-focus but only after re-render from state
   [:dispatch {::type ::reset-focus
               :scene-ref (-> event .getTarget .getScene)}])

raaon17:01:54

this kind of breaks the purity of even handler but is working hmm i guess the "right way" would be to introduce a :run-later effect that invokes dispatch! within fx/run-later

vlaaad21:01:37

@atdixon hmm, what about ext-focused-by-default? e.g. extension lifecycle that focuses the node when it's created and added to scene? I don't remember if we discussed this lifecycle before...

raaon21:01:26

oh no, we didn't - that will probably come in handy for some of my use cases for this particular use case, i have a list of items in a folder when the user switches the folder, a new list of items is created and i want to find (`.lookup`) the first one and give it focus so only one (the first) of the newly created items should get focused...

raaon21:01:11

i guess i could conditionally render the first one with the ext-focused-by-default , will try thanks @vlaaad !