This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-25
Channels
- # beginners (32)
- # boot (1)
- # cljs-dev (25)
- # cljsrn (1)
- # clojure (35)
- # clojure-dev (6)
- # clojure-nl (4)
- # clojure-russia (12)
- # clojure-spec (13)
- # clojure-switzerland (2)
- # clojurescript (63)
- # cursive (9)
- # datomic (18)
- # dirac (32)
- # graphql (6)
- # luminus (8)
- # off-topic (18)
- # pedestal (5)
- # protorepl (1)
- # re-frame (30)
- # remote-jobs (5)
- # untangled (61)
- # yada (7)
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))))
I want to inject it tough the token argument is not static, and should be declared in an effect fn
Are you saying the token
is in app-db
? Is that what you mean by it not being "static"
well…
routes/set-token!
appears to mutate something rather than obtaining something.
So I'm finding the question and the code confusing
I’m sure I am confused 😉
(defn set-token! [token]
(pushy/set-token! history token))
`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)})))
What am I doing wrong @mikethompson ?
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
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
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.
ex: “/” for :home or “/login” for :login
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)
Ok, so even though :set-url-token doesn’t write to db, this is not a coeffect
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
So now you need to write an "effect handler" for :pushy
effect handler!
Thanks!
Is it ok to put this inside a view fn?
(when (= (<sub [:active-panel]) :login-panel)
(>evt [:set-url-token :login-panel]))
When we see login-panel, force url to be /login…
Is it the right place?
I would avoid subscribing to stuff in the view if you aren't using it for rendering in some way
Ok, thanks!!
Thanks!
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 🙂