cljfx

https://github.com/cljfx/cljfx
2021-01-16T16:41:50.015200Z

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)

2021-01-16T17:26:44.015900Z

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

2021-01-16T17:38:19.016500Z

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)}])

2021-01-16T17:42:54.017700Z

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

vlaaad 2021-01-16T21:14:37.019Z

@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...

2021-01-16T21:16:26.020600Z

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...

2021-01-16T21:19:11.021500Z

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