Fork me on GitHub
#re-frame
<
2018-04-20
>
kucerm207:04:06

Hi, is it possible get header of response in http-xhrio effect success handler? I need to refresh token from request header but I don't know how πŸ˜•

robert-stuttaford08:04:19

have you reviewed the code, @kucerm2? if you don’t like what the code does, you could copy it into your project and modify it

kucerm208:04:43

review http-xhrio code?

ingesol13:04:51

I think this was answered here recently, you can configure it to return the raw goog.net.XhrIo, using this as your response-format: {:read identity :description "raw"}

ingesol13:04:01

Just tested it in my app, and it works

lilactown15:04:47

so I'm new to re-frame and trying to understand exactly how I would create a specific behavior: 1. A component is rendered that is subscribed to a certain field in the app-db 2. When the field in the app-db is gotten, it is detected whether it is nil or not a. if nil, the field's is changed to :loading and a network request is started that will eventually replace the value b. if not nil, then do nothing I'm trying to figure out how this fits into events, effects, coeffects, subscriptions... anyone know the best way to go about this?

ingesol22:04:49

Sounds like you're not too familiar with unidirectional data flow? your network request needs to be started by an event. The event could check if there's already data. Your remaining problem is how/when to trigger that event, I guess?

lilactown00:04:26

I'm familiar with unidirectional data flow. But I also am interested in isolating the concerns of my components data dependencies

ingesol15:04:47

Ok. So the principles are pretty simple: Your views subscribe to data, and dispatch events. Your subscriptions are pure and return content from the database.

ingesol15:04:02

Your remaining problem is how to trigger the network request, am I right? I made a framework for this, you could check it out to use it or get inspired to roll your own solution. http://ingesolvoll.github.io/posts/2018-04-01-kee-frame-putting-the-url-in-charge/

sandbags15:04:32

Hrmm... I amended my handler to use fn-traced but I still get "Code trace is not currently available for this event" in the dashboard.

sandbags15:04:45

Funny thing is, I only get this on the second time i trigger the event

sandbags15:04:29

I don't understand what happens the first time, but it shows me something in the Events tab

lilactown16:04:45

(continuing above) ultimately what I'm trying to do is do an initial server-rendering of my re-frame app using SSR πŸ˜… so I want to be able to detect when all of the page's data dependencies are done loading

lilactown16:04:04

right now I'm doing this by dispatch-sync-ing inside of a subscription 😬 is that taboo?

ingesol22:04:35

Very much so, I think you are breaking 2 or 3 rules at once πŸ™‚

ingesol07:04:59

Or am I wrong? Read this one, still not very excited about it though https://github.com/Day8/re-frame/blob/master/docs/Subscribing-To-External-Data.md

lilactown16:04:10

yeah, that page is pretty close to what I'm trying to do

lilactown16:04:12

I decided to eschew re-frame for now and use that model (of returning a ratom & triggering the request) with pure reagent + some other libs

sandbags16:04:45

Oh, actually it looks like re-frame-template may be rather behind version wise

sandbags17:04:33

Okay so it turns out, when I looked at the developer console that I was firing :events/foo rather than ::events/foo and I think this was causing the Event trace to break. Might be nice if 10x could trap these failed event dispatches and throw them up somewhere or, if it already does, somewhere more in your face.

sandbags17:04:48

otherwise i'd say this long looks very cool

kucerm217:04:40

Thank you i found it in cljs-ajax doc in response format section.

πŸ‘ 4
sandbags17:04:53

quite amazing actually (now I understand a little what I am looking at)

shaun-mahood18:04:16

@danielcompton I just got the function tracing in re-frame-10x set up - simply awesome!