This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-09-24
Channels
- # announcements (6)
- # architecture (9)
- # aws (2)
- # babashka (49)
- # beginners (160)
- # boot (19)
- # calva (9)
- # cider (16)
- # clj-kondo (17)
- # cljfx (9)
- # clojure (143)
- # clojure-australia (5)
- # clojure-berlin (1)
- # clojure-czech (3)
- # clojure-europe (64)
- # clojure-france (1)
- # clojure-italy (12)
- # clojure-nl (4)
- # clojure-spec (6)
- # clojure-uk (47)
- # clojurescript (27)
- # code-reviews (5)
- # conjure (45)
- # cursive (47)
- # datascript (2)
- # datomic (21)
- # events (1)
- # fulcro (9)
- # graalvm (4)
- # graphql (2)
- # jackdaw (22)
- # jobs (3)
- # kaocha (6)
- # london-clojurians (1)
- # luminus (4)
- # malli (19)
- # meander (136)
- # pathom (4)
- # pedestal (2)
- # re-frame (15)
- # reitit (2)
- # remote-jobs (2)
- # rum (12)
- # sci (1)
- # shadow-cljs (100)
- # spacemacs (10)
- # sql (1)
- # tools-deps (30)
- # vrac (1)
- # xtdb (30)
Hi, what’s the best way to subscribe to a list? Should I register a subscription for the whole list and then map across the elements with my view function, or is there some other way to subscribe to individual elements of a list that varies in length? I’m quite new to re-frame but I’ve read the tutorials once
Ok thanks
Nice flower logo, @U011J2CQT0F!
would it make sense for run-test-sync
to install an fx for :dispatch-later
that did an immediate dispatch?
You could write a test fixture to do that. Does run-test-sync
not automatically take care of that?
(defn dispatch-later-sync
[f]
(rf/reg-fx
:dispatch-later
(fn [value]
(if (map? value)
(rf/dispatch-sync (:dispatch value))
(doseq [effect (remove nil? value)]
(rf/dispatch-sync (:dispatch effect))))))
(f))
(use-fixtures :once dispatch-later-sync)
Maybe something like this would work for you.
Whether or not you should do it depends on your use case. If you have a test that hits some code using :dispatch-later
and it fails because the test finishes before the dispatch, then it probably makes sense.If you put it in a test fixture it will override for all tests. If it's inside run-test-sync then it will be removed at the end of the block
I’ve run into exactly the same problem:
(cond....
(:toaster-bus/bus db)
{:dispatch [:toaster-bus/remove curr-id]
:dispatch-later [{:ms (+ transition-ms 30) ;; once remove is finished add new
:dispatch [:toaster-bus/show message]}]}
Basically, it has to wait for animations to finish.
What I expected to happen was that run-test-sync
would:
• dispatch the first item (remove)
• which runs an animation to remove the toaster,
• when that is finished, removes the message from the db.
• Then the :dispatch-later
above kicks in, and
• adds the new message to the db,
• then runs the animation to show the toaster.
In my test, it looks like the :dispatch-later
is not happening, as the message after dispatching the initial message is the same.
@UDVJE9RE3 I tried your code, but it lead to this error:
re-frame: while handling [:toaster-bus/hide] , dispatch-sync was called for [:toaster-bus/remove-message] . You can't call dispatch-sync within an event handler.
Maybe I should just be using the async
stuff? I’ll have a look and see if that solves my problem.
Yes calling rf/dispatch-sync
is not allowed from reg-fx
I found out. It might be worth digging into re-frame a little and just calling the function registered to the :dispatch
fx directly in the test fixture code.
Oh, that is a good idea.