Fork me on GitHub
#re-frame
<
2017-12-24
>
chang01:12:51

Thanks for the pointers @kharper @atticmaverick Fixed it by setting :response-format to (ajax/json-response-format {:keywords? true}) partywombat

(rf/reg-event-fx
  :request-address-data

  (fn [_ [_ addr]]
    {:http-xhrio {:method         :get
                  :uri (str "" (name addr) "/balance")
                  :response-format (ajax/json-response-format {:keywords? true})
                  :on-success [:address-data-loaded]
                  :on-failure [:failed-get-request]}}))
My first time messing with ajax stuff 😄. Everything still feels like some magic but just woke up fresh so a good day is looming.

mikethompson05:12:23

@mohamedhayibor search for ;; IMPORTANT!: You must provide this. in the README :-)

razum2um08:12:21

btw, I wonder why so? maybe an opinionated default for json + (maybe) a warning can be better that pointing newcomers again and again

p-himik08:12:47

I'm trying to use https://github.com/vimsical/subgraph in my project, and all is fine, but one thing keeps bothering me. Namespaced keywords. Before SubGraph, if I had a component that works with some abstract datum that has :name and :link and doesn't care about what the datum represents, all is simple - I just extract :name and :link and that's it. With SubGraph, I have to add some namespaces. Now, if I want to be consistent and use nice #:my-ns {} syntax, I have to add ns to each and every key in each and every entity that I want to store with SubGraph. And here troubles begin - for the aforementioned component I now have to pass name-field and link-field everywhere it's used. I could of course rewrite SubGraph (and in fact, I've already done it, so now it almost doesn't resemble the original) so it would support fields without ns, but then entities relationships (like :composition/genre -> set of :genre/id) would be much harder to establish. Maybe someone could share some thoughts on or experience with namespaces in a similar matter - maybe there'are other trade-offs that I don't see that could help me make the choice.

Miloslav13:12:08

hi everyone!

Miloslav13:12:57

I have a question: how do I pass data to coeffect using inject-cofx?

Miloslav13:12:38

I'm trying to implement authorization. I have an fx-event registered for doing that, and it obviously needs a coeffect which is interacting with external auth api

Miloslav14:12:08

I'm passing credentials to my event that way:

(re-frame/dispatch [::auth credentials])
How do I pass that credentials to the coeffect?

Miloslav14:12:40

coeffect seems to be injected just before event handler function is defined, and I just cant figure out how do I do that

p-himik14:12:05

@melvoloskov > it obviously needs a coeffect which is interacting with external auth api It's not that obvious (albeit, I'm far from being an expert here). Could you describe what the workflow of your authorization is?

Miloslav14:12:47

user enters credentials, then the authorization event gets dispatched, then its being handled, but it needs a side-effect to call external auth api written in js, so there should be a cofx for doing that

Miloslav14:12:28

and user's credentials should be firstly passed to event and then passed to cofx handler

Miloslav14:12:52

the question is how to pass event data to its coeffect

jvuillermet14:12:28

It looks like you don’t need coeffect but an effect so you could write

reg-event-fx
...
{:auth creds} 
(that is if  auth is an effect that you registered with  reg-fx)
Maybe you can use the xhr effect like in here to call your external service https://github.com/Day8/re-frame-http-fx

jvuillermet14:12:56

so you would have

reg-event-fx ::auth
(fn [_ [_ credentials]
  {:http-xhrio ....}

p-himik14:12:48

@melvoloskov If it needs a side-effect, then it's an effect, not a coeffect. Like :http-xhrio, :dispatch and the like.

p-himik14:12:20

Effects are returned from your fx-handler, so you can pass any parameters you want there.

Miloslav14:12:55

but how do I return auth status code then

p-himik14:12:44

@melvoloskov In re-frame, there's no return in events. You'll have to use another effect for this, like :dispatch. E.g. :http-xhrio effect has :on-success and :on-failure parameters that accept events that will be dispatched in case of success or failure, correspondingly.

chang15:12:33

@mikethompson Haha I only have one new years resolution: to better read readmes 😃

zalky16:12:45

Hi all, I'm wondering if it is an anti-pattern to dispatch events in effects handlers?

zalky16:12:29

Specific example: I'm using re-frame.async.flow-fx to init my comms in an effects handler, and I'd like to dispatch a success event when it's done. I don't remember seeing anything in the docs about whether dispatching events in an effects handler is ok. It seems to work, and I'm not sure how else I would do it.

p-himik16:12:56

@zalky Take a look at this: https://github.com/Day8/re-frame/blob/master/docs/EffectfulHandlers.md#90-solution Instead of calling dispatch, you can just use :dispatch effect.

p-himik16:12:32

Oh, sorry, I misread effect handler as event handler. Yes, it's perfectly Ok to use dispatch in effect handlers.

razum2um08:12:21

btw, I wonder why so? maybe an opinionated default for json + (maybe) a warning can be better that pointing newcomers again and again