This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
I want to remove a query param from the address bar every time a certain action is dispatched. Would you recommend using an :after
interceptor, or writing an effect?
you can also take a look at the async reframe interceptor, it allows you to watch for certain events and dispatch new ones when certain conditions are met
Are you referring to this library? https://github.com/Day8/re-frame-async-flow-fx
hmm actually to link certain events with other events, why not just conditionally add :dispatch [:other-event args]
in the event handler, like while using reg-event-fx
?
I’d say that if it’s just one certain action it should be an effect. Interceptors are handy if you need same functionality around several different events.
Thanks! You could also kind of dispatch to the same effect from different event handlers, right?
Sorry for replying late! I’m poor at following these threads. But yeah, effects are reusable from event handlers. Re-Frame has stellar docs so I’ll just point you there for further info. 🙂 https://github.com/Day8/re-frame/blob/master/docs/Effects.md
Thanks!
hello, i have put together a simple app, but it doesn't work
(defn clicker []
(let [count (rf/subscribe [:count])]
[:div
[:div (str "The count is: " @count)]
[:button
{:on-click #(rf/dispatch [:increment-count])}
"Increment count"]]))
i have the above component
(rf/reg-event-db
:increment-count
(fn [db _]
(update db :count inc)))
the above event
(rf/reg-sub
:count
(fn [db _]
(:count db)))
the above subscription...
however, when i click the button in the component, i get an error
Uncaught TypeError: Illegal invocation
at Object.schedule (batching.cljs:63)
at Object.reagent$impl$batching$schedule [as schedule] (batching.cljs:113)
at Object.reagent$ratom$rea_enqueue [as rea_enqueue] (ratom.cljs:102)
at Object._handle_change (ratom.cljs:384)
at reagent$ratom$handle_reaction_change (ratom.cljs:338)
at Object.reagent$ratom$notify_w [as notify_w] (ratom.cljs:86)
at Object.cljs$core$IReset$_reset_BANG_$arity$2 (ratom.cljs:140)
at Object.cljs$core$_reset_BANG_ [as _reset_BANG_] (core.cljs:851)
at Object.cljs$core$reset_BANG_ [as reset_BANG_] (core.cljs:4476)
at fx.cljc:171
fwiw, it seems like the event fires correctly, but the subscription fails...not 100% sure 😞
full disclosure, i am using shadow-cljs and re-frame version 0.10.6 with reagent version 0.8.1
any help is greatly appreciated@nolan.wright.other bump shadow-cljs or set :compiler-options {:fn-invoke-direct false}
in the build config