This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-11-06
Channels
- # announcements (3)
- # aws (3)
- # babashka (9)
- # beginners (87)
- # calva (3)
- # chlorine-clover (7)
- # cider (6)
- # clj-kondo (1)
- # cljs-dev (31)
- # cljsrn (7)
- # clojure (26)
- # clojure-berlin (5)
- # clojure-europe (84)
- # clojure-nl (3)
- # clojure-uk (13)
- # clojurescript (39)
- # core-async (4)
- # core-logic (3)
- # cursive (3)
- # datomic (10)
- # devcards (5)
- # duct (2)
- # emacs (3)
- # events (1)
- # fulcro (6)
- # jobs (4)
- # kaocha (12)
- # london-clojurians (1)
- # off-topic (21)
- # other-languages (2)
- # pathom (5)
- # pedestal (1)
- # re-frame (1)
- # reitit (3)
- # remote-jobs (6)
- # reveal (6)
- # sci (34)
- # shadow-cljs (99)
- # tools-deps (99)
I’m having troubles getting a RN switch component to behave. When I switch it is briefly toggles back before toggling to the intended position again. I have a feeling it is because I am doing it the wrong way. This is the way I’m doing it (using re-frame):
(defn my-switch []
(let [enabled? @(rf/subcribe [:enabled?])]
[switch {:on-value-change #(rf/dispatch [:set-enabled (not enabled?)])
:value enabled?}]))
Seems like a common performance problem in using reagent + re-frame. You could try using dispatch-sync
+ flush
combo:
(defn my-switch []
(let [enabled? @(rf/subcribe [:enabled?])]
[switch {:on-value-change #(do (rf/dispatch-sync [:set-enabled (not enabled?)])
(reagent.core/flush))
:value enabled?}]))
And yes, reagent is in the mix too. The problem started to be noticeable when I moved the switch state down a notch in the app-db structure. So it is quite deeply nested.
I don't see why that could be a problem, but I don't know enough about re-frame's internals. I usually have to sprinkle the code with those declarations, last time it happened when using react-native-draggable-flatlist
. Sometimes I leave it as it is because the production build works a bit faster and the issue disappears there.
@pez You can also keep the enabled?
state in a local ratom.
(let [enabled? (r/atom @(rf/subscribe [:enabled?])] ...
Thanks! The sync-then-fush works great. With the local ratom I get a strange behaviour with it resetting on the first tap, then it starts to work. And, I think I see a slight performance difference. I have some content behind a (when enabled? …)
and that content is more delayed with the ratom solution. The delay seems to be about as long as the glitch I had without these mitigations, so maybe it is really more “honest”, rather.