This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-08-13
Channels
- # admin-announcements (8)
- # beginners (28)
- # boot (2)
- # bristol-clojurians (4)
- # cider (12)
- # clojure (177)
- # clojure-android (23)
- # clojure-canada (1)
- # clojure-dev (21)
- # clojure-italy (27)
- # clojure-korea (1)
- # clojure-russia (20)
- # clojure-spain (1)
- # clojurebridge (11)
- # clojurescript (156)
- # core-matrix (1)
- # cursive (2)
- # datomic (39)
- # events (1)
- # hoplon (13)
- # immutant (4)
- # javascript (2)
- # jobs (1)
- # ldnclj (13)
- # luminus (2)
- # melbourne (25)
- # off-topic (9)
- # onyx (13)
- # re-frame (110)
- # reagent (5)
How do I deal with a handler depending on another. Something like having a handler called get-user that request the user from the server, another got-user, that gets the data and puts it in the state, but now I have one called get-friends. Get-friends should only be run after get-user/got-user finished but I don’t want got-user to run get-friends as it’s not needed most of the time? Should get-friends do a dispatch-sync of get-user?
profil: what do you mean? I guess the answer is yes, but I don’t see how that helps.
How do I wait for got-user to run to then dispatch itself?
profil: here you have some sample code: http://stackoverflow.com/questions/31985649/how-to-have-handlers-run-sequentially-in-re-frame
@pupeno: ahh, I guess you would have to dispatch it from got-user then, you could parameterize it
profil: but got-user is used in every single page while I want to fetch the friends only in one page.
dispatch-sync can’t be used inside a handler
Every piece of information fetched from the server will depend on the user, which means that if I fetch that information in got-user, got-user will downloading a humongous amount of data that will mostly not be used.
I could pass around next-handler but it feels like continuations, which are hard to debug, and I bet I’m not the first one to deal with this. I could copy code, but then I think I’ll end up with a lot of duplication.
dispatch itself then, until you have got a valid user, in get-friends (when (nil? (:user db)) (dispatch [:get-friends]))
Do you mean:
(if (nil? (:user db)) (do (dispatch [:get-user]) (dispatch [:get-friends])) (ajax-call-to-get-friends))
Ah, that’s better.
It still feels a bit convoluted… for example, if I have 5 or 6 sequential calls.
I don’t know yet as I haven’t build a complex SPA before, but my server apps got complex enough where we needed to interact with 10 different models or more in a single render. I can see that turning into several requests to the server API.
what is the correct way of having a parent component P conditionally display child component A or child component B (based on atom data and secretary route), when i switch from one state to the other the view does not get updated properly?
(defn p []
(let [a-or-b-state (subscribe [:something-important])]
(fn []
(if @a-or-b-state
a
b))))
escherize: have a look at the paste, i think i am using the exact same approach , bbut the view only updates the first time
@shaym: i think page-function
needs to either be a reaction, or it needs to be in the render part of a form-2/3 component
you think that form 2 without another reaction will work, or it needs the page-function reaction
form-2 without a reaction would work, if you do the @page
part inside the render function
(defn body-main[] (let [page (subscribe [:current-page]) page-function (get pages @page)] (println "page is " @page) (fn [] page-function) ))
(defn body-main[] (fn [] (let[[page (subscribe [:current-page]) page-function (get pages @page)]] page-function) )
(defn body-main []
(let [page (subscribe ..)]
(fn []
(let [page-function (get pages @page)]
[page-function]))))
i used the above form , if i return a vector i get an arity error , without it i still get partial rndering
def pages {:project-list [project-table] :project [project-page]}) (defn body-main[] (let [page (subscribe [:current-page]) ] (fn [] (let [page-function (get pages @page)] (println "page is " @page) page-function) ) ))
on first navigation from :project -list to :project , the data from :project is displayed but one button from :project-list is also showing , when i click browser back , and it switches back to :project-list , the table which was originally there is missing
after multiple back and forth navs i get ......Uncaught Error: Invariant Violation: ReactMount: Two valid but unequal nodes with the same
and 14 hmm it's wrong because again you're dereffing a subscription outside the render function
i can see the need of returning a function rather then calling a function , but i must admit i am confused as to how many times it needs to be wrapped in a vector , when having a chain of function calls
yes, or in a reaction. i think things can still seem to be working ok even if you do the deref outside, but it will cause the component to be re-rendered on any change to app-db
i might be confusing things though, maybe that's what happens if you do a subscribe inside the render function :P
ok the 2nd thing i said was correct, as per re-frame readme: Eek! subscription in renderer
... Why is this wrong? Well, this component would be re-rendered every time app-db changed
i am wondering which is better/easier a chain of functions where the last one returns a vopm , or a chain of componenets nested within each other?
well a chain of components feels "safer" to me, but i've yet to turn this feeling into an actual explanation i can reason about ;p
@mikethompson is usually good with putting stuff into words ;)