Fork me on GitHub
#re-frame
<
2019-01-10
>
aria4219:01:58

Another n00b question, but what is the preferred way to dispatch initialziation events associated with a component (outside of using an form-3 component). The docs have examples of initializing the entire app, but that's not a applicable inside a component body. Is the solution to try to be idempotent?

lilactown19:01:51

mainstream opinion w.r.t. re-frame is that you don’t associate events with rendering a particular component

lilactown19:01:21

usually, rendering a particular component is associated with a user event. your state change then should happen in an effect that’s associated with that particular user event

hoopes19:01:06

I’m struggling a bit with http-xhrio. I would like to have a chance to process the data returned from the ajax call before it is dispatched to the :on-success handler. This way, each :on-success handlers doesn’t have to do the processing itself. There are :interceptors in cljs-ajax, but they run before the :response-format interceptor, so all I get is the response text as a string - I’m really trying to process the result of converting the text response into a cljs map, which happens in the :response-format function. I was toying with the idea of detecting the :on-success vector, and replacing it with one of my own that gets the response and dispatches the original :on-success with the processed data, but then I started to get that feeling where “boy this seems harder than it should be”, so I’m asking the experts for any ideas.

lilactown19:01:36

what about an interceptor that each event-fx would use?

hoopes20:01:26

i would still need to use that interceptor on every event that handles the ajax result, right?

hoopes20:01:45

(you mean a re-frame interceptor in this case, correct?)

hoopes20:01:51

i’m trying to put myself in a situation where the on-success handlers of any ajax call don’t have to remember to add an interceptor, or process the data the same as all the other success handlers, because i’m gonna wind up with one that forgets, and have unprocessed data in my app db, and slowly die as i try to debug that 🙂

lilactown20:01:40

well, you could rewrite the http-xhrio effect

lilactown20:01:09

either way, it’s going to be gross. I think having a common interceptor that most event-fx can use would be the way I would try to do it

lilactown20:01:00

it would also ensure that if later I need to do some special-cased processing of the response, I don’t have to write a bunch of cases into my http layer… I can just write a new interceptor

lilactown20:01:06

or not use the interceptor at all

hoopes20:01:24

true enough - i suppose if i put all ajax success handlers (of a certain type) in teh same namespace, i can def it in there, and come close to not having to remember