This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-01-16
Channels
- # ai (3)
- # babashka (3)
- # beginners (252)
- # calva (56)
- # clj-kondo (6)
- # cljfx (7)
- # cljs-dev (2)
- # cljsrn (2)
- # clojure (72)
- # clojure-france (12)
- # clojurescript (13)
- # conjure (60)
- # garden (18)
- # hoplon (16)
- # jobs (1)
- # leiningen (3)
- # off-topic (18)
- # pathom (5)
- # practicalli (1)
- # reagent (4)
- # reitit (1)
- # remote-jobs (1)
- # reveal (3)
- # shadow-cljs (1)
- # spacemacs (7)
- # xtdb (39)
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)
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)}])
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
@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...
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...