Fork me on GitHub
#re-frame
<
2017-06-25
>
leontalbot00:06:34

Hello! I have this coeffect (is it?)

(re-frame/reg-cofx 
 :set-url-token
 (fn [cofx [_ token]]
   (assoc cofx :url-token (routes/set-token! token))))

leontalbot00:06:38

I want to inject it tough the token argument is not static, and should be declared in an effect fn

mikethompson00:06:29

Are you saying the token is in app-db ? Is that what you mean by it not being "static"

mikethompson00:06:38

routes/set-token! appears to mutate something rather than obtaining something.

mikethompson00:06:59

So I'm finding the question and the code confusing

leontalbot00:06:22

I’m sure I am confused 😉

leontalbot00:06:39

(defn set-token! [token]
  (pushy/set-token! history token))
`

leontalbot00:06:28

Here is the effect fn:

(re-frame/reg-event-fx
 :set-active-panel
 [(re-frame/inject-cofx :url-token panel)]
 (fn [cofx [_ panel]]
    (let [db (:db cofx)]
      {:db (assoc-in db [:persistant :active-panel] panel)})))

leontalbot00:06:52

What am I doing wrong @mikethompson ?

mikethompson00:06:18

I'm going to leave that to someone who understands pushy and routing better than I. But I'd recommend that you describe: 1. what is doing the (dispatch [:set-active-panel XXX]) 2. what you want the :set-active-panel event handler to do

mikethompson00:06:19

Regarding 1 I'm assuming there is some navigation mechanaism (tabs, sidebar, etc) and as the user interacts with it, there is a dispatch Regarding 2 I'm assuming you want to: A. change some state in app-db (so UI redraws correctly) B. do something with pushy so it remembers the current route

leontalbot00:06:29

1. (dispatch [:set-active-panel :home]) writes in db what panel (view chunk) should be displayed. (in this case, it would be :home which I want to display on screen. 2. As I want to write to db to set the keyword representing the active panel, I also want to push the new url with pushy.

leontalbot00:06:07

ex: “/” for :home or “/login” for :login

mikethompson01:06:08

If I'm understanding correctly, that means: * You do NOT need a coeffect (re-frame/inject-cofx :url-token panel) because you are obtaining nothing from pushy * Your event handler has two effects (it wants to make two changes to the world)

leontalbot01:06:17

Ok, so even though :set-url-token doesn’t write to db, this is not a coeffect

mikethompson01:06:25

So I'd imagine something more like this:

(re-frame/reg-event-fx
 :set-active-panel
 (fn [cofx [_ panel]]
    (let [db (:db cofx)]
      {:db (assoc-in db [:persistant :active-panel] panel)
       :pushy  some-url })))                      ;;  <---   this is new

mikethompson01:06:54

So now you need to write an "effect handler" for :pushy

leontalbot01:06:03

effect handler!

leontalbot03:06:23

Is it ok to put this inside a view fn?

(when (= (<sub [:active-panel]) :login-panel)
              (>evt [:set-url-token :login-panel]))

leontalbot03:06:12

When we see login-panel, force url to be /login…

leontalbot03:06:19

Is it the right place?

curlyfry10:06:29

I would avoid subscribing to stuff in the view if you aren't using it for rendering in some way

curlyfry10:06:05

I'd keep that logic in whatever function is changing the active panel

leontalbot11:06:18

Ok, thanks!!

piotr-yuxuan10:06:27

Hiya! I know it’s not really tied to re-frame but I’m trying to use effectful effect re-frame-http-fx and I stumble CORS issue. However I stick to the example provided in the readme, so I’m a bit puzzled. I’ve described my issue here: https://github.com/Day8/re-frame-http-fx/issues/15 Any advice would be much appreciated 🙂