Fork me on GitHub
#re-frame
<
2016-08-15
>
superstructor02:08:43

@mikethompson: with the new reg-fx effects handlers, how would one implement an effect that has no parameters or values required ? e.g. mount-root as an effect ?

(reg-event-fx
  :auth
  (fn [{:keys [db]} [_ response meta]]
    {:db db
     :mount-root nil}))

mikethompson02:08:34

Hmm. I didn't envisage any) effect handlers having no data. So that's a good question.

mikethompson02:08:41

I guess nil is good enough?

mikethompson02:08:48

Looks odd though

mikethompson02:08:17

Are you sure you don't want to add a parameter 🙂

superstructor02:08:22

Indeed it does look odd 🙂

mikethompson02:08:27

The string id of the mount element ?

superstructor02:08:37

😆 not a bad idea, solves the problem by providing something. Might come up again though ? Surely there are effects that have no data ?

mikethompson02:08:21

All the ones I've created so far have had data

superstructor02:08:20

@mikethompson: Document.exitFullscrean() ? To be honest, I had to think pretty hard to come up with a side-effecting web api that doesn’t require some kind of data so maybe effects requiring data is a reasonable proposition.

mikethompson02:08:30

Okay, we'll run with nil in those cases at the moment

mikethompson02:08:42

I'll add something to the docs. I'm currently work on them. Uggh

mikethompson02:08:15

In 8.1 we'll have to focus on coming up with the best possible set of builtin effects

superstructor02:08:32

:thumbsup: sounds reasonable, thanks.

superstructor02:08:02

on a related note, do you think its is reasonable to make all effects fx handlers ? e.g. mount root element, start router, set route, cookies set/delete, injecting css etc.

mikethompson02:08:25

There's a trade-off. On the one hand, you can get away with doing it the non-pure way. On the other hand, it will hurt your testing story. And your event replay story (related to debugging).

mikethompson02:08:43

So it depends where that balance falls for you

mikethompson02:08:23

effort vs reward

mikethompson02:08:09

I'm was initially surprised to see mount-root-element in there. But actually that's probably quite reasonsable.

superstructor02:08:39

Yeah I wasn’t expecting it either until I got to the porting effort, and in code it seems to make sense.

superstructor02:08:19

looks good :thumbsup: thanks.

superstructor02:08:59

what is the recommended way to publish fx handlers ? like our cookie handler ? do we just publish something on https://github.com/SMX-LTD/re-frame-cookie-fx ?

mikethompson02:08:34

Yes, I'm thinking that we'll create a Wiki page where people can add theirs to the list of publically available effect handlers

superstructor02:08:57

Ok sounds good, thanks.

superstructor05:08:04

@mikethompson: just looking at interceptor.cljc implementations and wondering how to write the equivalent of log-ex from the debugging event handlers wiki page these days ? looks like an interceptor no longer calls the handler fn so cannot try/catch ?

mikethompson05:08:21

Yeah, Interceptors don't allow for try catch.

mikethompson05:08:37

I'll have to look at that page to remind myself

mikethompson05:08:12

Oh that's right. That's from the bad old days when exception stacks were lost when an exception was rethrown.

mikethompson05:08:26

So not really required any more

superstructor05:08:22

Oh I didn’t realise it wasn’t really required anymore. My bad. Thanks! 🙂

joshkh10:08:17

Hi Mike, I've been playing a bit with async-flow-fx and I have a quick question. I set up a simple test case where I'd expect the :do-Y event to dispatch, but it doesn't. I only get as far as seeing the :success-X effect occur:

(reg-event
  :do-Y
  (fn [db]
    (println "reg-event :do-Y has fired")
    db))

(reg-fx
  :success-X
  (fn [val]
    (println "reg-fx :success-X has fired")))

(reg-event-fx
  :do-X
  (fn [{db :db}]
    (println "reg-event-fx :do-X has fired with db" db)
    {:db db
     :success-X nil}))

(defn boot-flow
  []
  {:first-dispatch [:do-X]
   :rules [{:when :seen? :events :success-X  :dispatch [:do-Y]}]})

(reg-event-fx
  :boot
  (fn [_ _]
    {:db db/default-db
     :async-flow (boot-flow)}))
Any clues to my misunderstanding?

mikethompson11:08:28

success-X needs to be an event.

mikethompson11:08:02

async-flow is about events

mikethompson11:08:27

You seem to have success-X effects

mikethompson11:08:15

So the idea is that you dispatch the do-X event and there will then be either a success-X event or a fail-X event

joshkh11:08:46

Ah yes, I caught that and changed it since then, but still no dice.

joshkh11:08:39

(Which I'm sure is a problem on my end)

mikethompson11:08:42

clj
(reg-event-fx
  :do-X
  (fn [{db :db}]
    (println "reg-event-fx :do-X has fired with db" db)
    {:dispatch  [:success-X]}))    

joshkh11:08:13

But on a side note, I tried implementing forward-events-fx instead, and came across a different problem. I have a function (from the re-frame template) that handles setting the active panel. I've made it effectful so that I can listen for when my app has finished loading. The idea is that if w:

(reg-event-fx
  :unqueue
  (fn [{db :db}]
    ; Finally redirect the user
    db))

(reg-event-fx
  :set-active-panel
  (fn [{db :db} [_ active-panel panel-params]]
    (if (:fetching-assets? db)
      {:db             (assoc db :queued {:active-panel active-panel
                                          :panel-params panel-params})
       :forward-events {:register    :abc
                        :events      #{:finished}
                        :dispatch-to [:unqueue]}}
      {:db (assoc db :active-panel active-panel
                     :panel-params panel-params)})))
When I run this, re-frame throws an error for each subscription that would otherwise be updated on the view: > core.cljs:3679 re-frame: no effects handler registered for: :active-panel . Ignoring

joshkh11:08:11

Oh, of course, I didn't return the world as a map.

joshkh12:08:51

Anyway, thanks again for the help. In the future if these basic questions come up would you prefer that I post them to stackoverflow instead?

mbertheau12:08:47

Why is it wrong to call subscribe inside a reaction? This is stated in question 2 in the FAQ, https://github.com/Day8/re-frame/wiki/FAQ but it isn't explained.

hjrnunes16:08:50

hi guys, I’m wondering what’s the current thinking re. url routes. ATM I’m using the routes to drive navigation e.g. push a url to history and the url dispatcher calls re-frame dispatches accordingly which go do their thing. It seems to be working fine for now, but it’s not clear whether it will scale for more complex paths. Furthermore, I’m pushing the urls straight from the views i.e. not using dispatch. The only alternative I can think is to dispatch a url push event, handler then pushes url to history, url matcher dispatches more events accordingly. Any suggestions?