Fork me on GitHub
#re-frame
<
2017-03-20
>
negaduck11:03:36

@markel, I did auth with openid connect, and it had little to do with re-frame, because the main part is opening a pop-up with authorization request. Then after all redirects you should land to a page which calls some code from your app: window.opener.your_project_name.core.dispatch_login('{{ id }}’); and then closes itself.

negaduck11:03:49

I think oauth is not too different

PB13:03:39

Hey all… I’m running into something interesting and I was hoping someone could explainw hy I’m seeing this. My db atom has a key :projects. Projects is a collection of maps, as such. [{:name “some-name” :other-field “somefield”} {:name “some-woof” :other-field “somewoof”}] Sometimes I detect a change to one of the projects and as a result make an api call to fetch the new one. This is where my issue raises it’s head. I cannot think of a nice way to update the specific project map I want with the result of my api call and as a result I have to do something like this:

(re-frame/reg-event-db
 :good-get-project
 (fn [db [_ project-name result]]
   (let [project (util/find-project-by-name project-name (:projects db))]
     (println "moo")
     (update db :projects #(do (remove #{project} (:projects db))
                                       (merge % result))))))
Now when I run this. Something weird happens. moo gets printed to my repl continuously until I leave that page. Can anyone tell me why?

negaduck13:03:57

@petr, I’m not sure, where does the api call happen? And what about having your projects in a map instead of a vector, like :projects {:name “some name” {:its-properties :etc} :name “some-woof” {…}} and then update them using update-in?

PB13:03:22

@negaduck That is something I had considered. I’m not in love with it but would do it if it came down to it. I’m very confused as to why it seems to be in a loop. Does it have to do with the view having a subscription to the :project key of the db?

PB13:03:16

I had also considered something like :projects {:some-name {…}, :some-woof {...} }

negaduck13:03:46

I don’t see the api call, and how you detect changes on one of projects. It could be detecting a change, firing an update, then detecting it again and firing an update, etc, recursively.

negaduck13:03:42

just a hypothesis

PB13:03:34

@negaduck the api call is super simple:

(re-frame/reg-event-fx
 :http-get-project
 (fn [{:keys [db]} [_ job-name]]
   {:db (assoc db :show-twirly true)
    :http-xhrio {:method          :get
                 :uri             (str "" job-name)
                 :timeout         8000
                 :response-format (ajax/json-response-format {:keywords? true})
                 :on-success      [:good-get-projects]
                 :on-failure      [:bad-http-result]}}))
It is called as such on the view:
(let [project-title @(re-frame/subscribe [:params])
        _  (re-frame/dispatch [:http-get-project project-title])
        projects @(re-frame/subscribe [:projects])
        project (util/find-project-by-name project-title projects)]
    [re-com/v-box
     :gap "1em"
     :children [[somethings]])

PB13:03:42

I think that’s whats happening

negaduck14:03:12

@petr, Can it be the following? When you are subscribed to project-title, when it changes, you fire an ajax request that again triggers update of project-title.

negaduck14:03:09

I’d check if it also sends ajax requests continuously along with that println.

negaduck14:03:39

I think this is because your view isn’t pure function, it dispatches events, and it shouldn’t

PB15:03:37

@negaduck I think this is because your view isn’t pure function, it dispatches events, and it shouldn’t. I’d love to know the correct pattern for doing this

PB15:03:34

I very much agree with that. I just don’t know where else this would belong

negaduck15:03:52

@petr, views should be pure functions of app state, like v = f(s), you are almost there, just put that dispatch out of your view somewhere. You could also reg-cofx to use it in :init-db event

negaduck15:03:29

well, you don’t need cofx, just reuse that :http-xhrio part

ericnormand17:03:22

hey everybody

ericnormand17:03:59

I'm doing research for a re-frame course

ericnormand17:03:07

I'd love your input

ericnormand17:03:39

it's a quick survey about your struggles with re-frame

sandbags18:03:41

what struggles?

sandbags18:03:06

ah okay, also ClojureScript and more generally

sandbags18:03:17

@ericnormand personally i don't like how you have phrased your money questions. I appreciate what you're doing but as one data point, I find it hard to evaluate that in advance of seeing what your solution is and I can't imagine all the possible solutions (even in course form) to my 'frustration'. Is a course/video even a good answer to those. It seems backwards to me. But, as I say, just one mans data.

ericnormand18:03:29

Thanks for the data point

ericnormand18:03:51

do you have any frustrations with re-frame?

ericnormand18:03:01

how much would it be worth to you to get rid of them?

ericnormand18:03:04

that's all I'm asking

ericnormand19:03:52

if you could make it go away, how much would you pay?

danielcompton20:03:54

@ericnormand if you read through the history logs of this slack channel you should find a bunch of people's questions about re-frame which would be good to mine for course material

mccraigmccraig23:03:18

@ericnormand something about the "How much would be TOO EXPENSIVE to spend to solve your frustrations?" and subsequent questions rubbed me up the wrong way and made me bail on the questionnaire. if there was a magic wand and i could get the REALLY GOOD DEAL (and retain the knowledge) then i would certainly pay, were it feasible - but i'm not yet confident that the wand or deal even exist!