This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-01
Channels
- # aleph (4)
- # arachne (24)
- # beginners (231)
- # boot (4)
- # cider (63)
- # clara (36)
- # cljs-dev (57)
- # clojure (195)
- # clojure-dev (12)
- # clojure-gamedev (2)
- # clojure-greece (1)
- # clojure-italy (10)
- # clojure-poland (4)
- # clojure-spec (36)
- # clojure-uk (65)
- # clojurescript (133)
- # core-async (8)
- # core-logic (2)
- # cursive (18)
- # data-science (3)
- # datomic (58)
- # defnpodcast (3)
- # duct (2)
- # emacs (2)
- # fulcro (27)
- # graphql (3)
- # hoplon (18)
- # jobs (2)
- # jobs-discuss (10)
- # jobs-rus (1)
- # lumo (1)
- # mount (6)
- # nyc (2)
- # off-topic (27)
- # pedestal (13)
- # re-frame (71)
- # reagent (105)
- # reitit (4)
- # ring (2)
- # ring-swagger (1)
- # rum (10)
- # shadow-cljs (172)
- # spacemacs (24)
- # sql (26)
- # tools-deps (1)
- # uncomplicate (4)
- # unrepl (51)
- # vim (3)
- # yada (11)
@pmooser hard to say without knowing specifics, but a couple of things to watch out for: https://presumably.de/reagent-mysteries-part-2-reloading.html
Do the new docs yet document React keys?
i wrote a little section on that but i’m not sure it made it in. https://gist.github.com/jmlsf/17c588deb326e538dcea6847bc66db9b#keys
if you think that should be done differently or more thoroughly feel free to steal it and edit it
@lee.justin.m can you modify the examples to show them in the context of a seq like for
Yeah, I'm thinking about writing why they are needed etc. and comparison between workarounds (and what they do and why they aren't as good as real unique keys)
Thiis is probably one of the most common things I mention during reviews and looks like this isn't documented yet
@juhoteperi if you want to take that on I would be very appreciative. feel free to use any or none of what i put together. it really needs to be written and probably be in its own section. we should probably put references to it in the sequences section and the creating components section too
hm never mind there isn’t a sequences section. we just mention it obliquely in the faq at one point
Feel free to steal from https://presumably.de/reagent-mysteries-part-1-vectors-and-sequences.html
Hi all, I’m fairly new to reagent w/ previous knowledge of om.next. I’m trying to simply figure out how to pass route params into a component, but all attempts fail. Here’s the code, anyone have any ideas? https://gist.github.com/njj/cdc852e51e255e99b62946a13565a665#file-foo-cljs-L31
@njj i just stick the params in the router atom and then my top level component pulls from the atom and passes as a param
the sample code you pasted puts the actual component in the atom. i don’t do that. i put a keyword that represents the component and then in my top-level router component i just have a case statement
(secretary/defroute "/app/notebook/:notebook-id"
{notebook-id :notebook-id}
(reset! current-route {:page :notebook
:notebook-id (str->int notebook-id)}))
then later I check for the value of :page
and return a hiccup form with the right component and pass the parameters to that i grab from :notebook-id
i had to edit out a bunch of stuff, but I think this is right:
(defn router-component
[]
(debug-fmt "routing to %" (:page @current-route))
(case (:page @current-route)
:notebook [home-component {:view :notebook :notebook-id (:notebook-id @current-route)}]
;; more cases here
[:div "Page not found."]))
(defn mount-root []
(reagent/render [router-component]
(.getElementById js/document "app")))
there’s not thing special about it. you just need a component at the top level which derefs some kind of router state and returns the right component
i like things nice an explicit so i shy away from the techniques that use multimethods and weird stuff like that
@lee.justin.m does your current-route just look like:
oh sorry i confused my self above. yea current-page
is more similar to my router-component
and page
is similar to my current-route
the only difference is that instead of putting the component in the ratom and using it directly in current-page
you would put data in the ratom and just return the hiccup based on that data
now that i’m thinking about it, you could actually avoid my case statement by just putting hiccup in the router ratom
like instead of
(reset! current-route {:page :notebook
:notebook-id (str->int notebook-id)})
i should probably just do (reset! current-route [notebook-component blah blah blah])
and then just have my router-component look like your current-page
i don’t know why i didn’t think about that before. i had run into the same problem you are having but my solution is a little clunky
it would be easier (and more like what you are doing) if I just did this:
(defonce current-route (reagent/atom [home-component]))
(secretary/defroute "/app/notebook/:notebook-id"
{notebook-id :notebook-id}
(reset! current-route
[home-component {:view :notebook
:notebook-id (str->int notebook-id)}]))
(defn router-component
[]
@current-route)
I haven’t tested but that should work@lee.justin.m ends up being something like, https://gist.github.com/njj/cdc852e51e255e99b62946a13565a665
oh that’s because you’re doing [step-page {:step-id step-id}]
instead of [step-page step-id]
Supposed I’m using an imbedded component with ‘:>’ notation, and it has a ‘refs’ property with a name I pass in. Later on, I’ll need to access the component by that name to access its data. What’s the best way to do that?
@lee.justin.m @juhoteperi if writing docs on keys, feel free to use this material ... https://stackoverflow.com/questions/37164091/how-do-i-loop-through-a-subscribed-collection-in-re-frame-and-display-the-data-a/37186230#37186230
I had it down to do a refs.md
using that material as a base, but would be very happy to see someone else do it
@jmckitrick i’m not quite sure what you are trying to do
Hmm. Let me poke around a bit more, @lee.justin.m
@lee.justin.m does your home component look for the :view
and then switch on that?
https://github.com/reagent-project/reagent/blob/master/docs/UsingHiccupToDescribeHTML.md
(defn router-component []
@current-page)
(defn mount-root []
(r/render [router-component] (.getElementById js/document "app")))
exactly. for me, realizing that all you are doing is writing functions that return plain clojurescript vectors (i.e. hiccup), was a major revelation in how reagent works. because i was pretty new to cljs, this kind of thing (defn hi [] [:div "hi"])
looked like magic syntax to me. but it isn’t. it’s just data and nothing will happen to it until you pass it to reagent
so the router-component
, which seems to do nothing, actually does do something: it reacts to the current-page
mutations
again, even if you do that, r/render
doesn’t know to re-render when current-page
mutates
(defn mount-root []
(r/render [(fn [] @current-page)] (.getElementById js/document "app")))
#(@current-page)
is same as #([a vector here])
i.e. it will try to call the vector as function
Supposed I’m using re-frame, and after an ajax request succeeds, I want to issue another one. Is it permissible to dispatch
an event from inside an event handler?
@jmckitrick yes, you'd use the :dispatch
effect.
But you wouldn't use dispatch
directly, because that would be sideeffecting
Hmm. So what’s the correct way?
BTW, there is also a #re-frame channel
Ah, perfect.
Be sure to read the docs :-)
Will do, thanks for the reminder. I’m working my way through the Eric’s videos, and forgot about the deep docs I hadn’t gotten to yet.
That’s one area where re-frame shines: the docs