Fork me on GitHub
#re-frame
<
2019-04-28
>
ackerleytng04:04:22

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?

lmergen12:04:00

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

ackerleytng13:04:41

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?

valtteri13:04:02

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.

ackerleytng00:04:15

Thanks! You could also kind of dispatch to the same effect from different event handlers, right?

valtteri18:05:28

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

Nolan17:04:45

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

thheller17:04:23

@nolan.wright.other bump shadow-cljs or set :compiler-options {:fn-invoke-direct false} in the build config

thheller17:04:57

I changed the default but reagent somehow didn't like that so I reverted it

thheller17:04:16

you are probably on 2.8.32 which has the bad default

Nolan17:04:17

ah, yes i was using version 2.8.32

Nolan17:04:22

bumping fixed the issue

Nolan17:04:26

thanks thheller

Nolan17:04:32

thought i was going crazy