Fork me on GitHub

Hello all, I dumb question, is there any way to get information from session after http-xhrio call?


I have this component which consists retrieves form data from the server and displays it and allows editing as well. So in my app-db has the structure as follows:

{ :form-data {...}
  :editable-form-data {...}}
The editable-form-data stores the UI changes which haven’t been persisted yet. So at the initial load of the component I make the xhr call to server to get the form-data which also needs to be copied over to editable-form-data field. Right now there a db-event which assocs the result of xhr call to both the fields in app-db. This works but it feels hacky to be honest. Are there any suggestions on doing this better?


That seems pretty sensible. You could also make use of local state in your reagent components to keep the edited state but that's probably harder


Is there a kind of dual/equivalent of the effectful handlers for subscriptions that side effect or call out to javascript land. I'm looking at making a subscription for window dimensions in react native


danielneal: I don't believe there is anything like that. Is there a reason the dimensions cannot be put into the app-db and have the subscription use that?


@U051H1KL1 I dunno about native, but in the browser you'd do this:

(.addEventListner js/window 
    (fn [event] 
       (dispatch [:resize  XXX])))
Then, in the event handler for`:resize`, you'd put the new size details into app-db And then subscribe from app-db as normal. The XXX would have to be replaced with code that got the current size information and added it to the event being dispatched.


ah cool, yep, I think it will work in native just like that


there's a similar global event listener I can add


Hi, I found that in projects generated by re-frame-template , there is a (defn ^:export init [] ... ) entry function. May I ask which library need this entry? re-frame reagent or cljsbuild? Thanks!


Ahh… I see, it is called by the js in index.html in app.core.init().


Does anyone know of a place in the reagent / re-frame docs that warns against out-of-date subscription values being used in event handlers?


In other words, always use the app-db as a source of truth, not the values that are liable to change during the lifecycle of a reagent component.


Using re-frame.test/run-test-sync I’m getting ERROR You can't call dispatch-sync within an event handler. for handlers that return :dispatch fxs. Is there a workaround that doesn’t involve running async?

Doug Kirk16:05:48

If an interceptor places a map into the co/effect part of the context, does that persist to the next dispatch call, or is the db the only thing that persists?


Hello all, I´m doing this

   [{:keys [db]} [_ usuario senha]]
   {:db (assoc db :opcoes-dialogo {:dialogo-ativo :carregando
                                   :titulo "AGUARDE !!!"
                                   :tipo :normal
                                   :mensagem "Validando credenciais ..."
    :http-xhrio {:method :get
                 :uri "/login"
                 :params {:usuario usuario :senha senha}
                 :format          (ajax/url-request-format)
                 :response-format (ajax/json-response-format {:keywords? true})  
                 :on-success [:login-ok]
                 :on-failure [:login-erro]}
Then in /login I´m returning a JSON that contains ok or error for user and password validation. When ok, I set into session the value for authenticate 'ok' in response from server. Is there any way to see session :authenticate 'ok' in :on-sucess callback?


@fabrao, I’m not sure I understand the question. Do you want to read the json? What about the following?

 (fn [db [_ result]]
   ;; do whatever you want with the result here
   ;; like (assoc db :authenticate (:authenticate result))


I want to get the session value passed from server


that link above (the right one) should help you. basically, the result is passed into the :on-success handler as the last parameter


the question is probably about reading a response header when :response-format is set to ajax/json-response-format


I asked a question in off-topic which is related to re-frame, so I link it here too.


@jfntn we're looking into it. Stu will create a ticket


@kirked context is created fresh each event


@fabrao, apparently, there is no easy answer, look into cljs-ajax interceptors:


@mikethompson cool, thanks for the update, running async works for now


@jfntn there's work currently happening on a branch, which we hope to release in the next couple of days