Fork me on GitHub
#re-frame
<
2017-03-24
>
tagore00:03:10

I'm curious about how people are handling routing in re-frame apps. Secretary seems fine for route matching, but I'm (perhaps out of ignorance) a bit dubious about accountant- seems like just a bit too much magic for my tastes at first glance. I've done a fair bit of react/redux with the react-router for redux, and while I think it has some issues (especially around asynchronicity) it does do some magic that I kind of like. Is this a case where people wind up rolling their own with re-frame, or am I missing a library?

tagore00:03:06

I should add that I've been in npm-land long enough now that I've really started to lose my roll-my-own instincts.

willier01:03:50

I'm using bidi for routing and accountant for history. Here's the example: https://github.com/PEZ/reagent-bidi-accountant-example

pez07:03:09

I’m sure you mean you are using Accountant for history, right? 😄

tagore02:03:37

@willier Thanks, that answers my question, and gives me a starting point.

tagore02:03:11

I'm inclined to think, based on my experience writing SPAs in Angular and React/Redux, that having an easy default way of handling routing is crucial.

armed07:03:50

Hey, folks. How do you manage app-db with 3+ depth? My handlers looks like that:

(reg-event-db
 :select-report
 (fn [db, [_ id]]
   (assoc-in db [:report-section :selected-report :id] id)))
Is it normal in re-frame?

gklijs07:03:47

I have it on some maps. But I also have seperate method for some large maps. You could a function set-id and then use it to be something like

(set-id db id)
It add a level of abstraction which you may or may not like, but makes the event handler look more clean.

armed08:03:48

@gklijs thanks, came to same idea.

armed08:03:25

was using setters for such updates, but had to ask community to be sure.

armed08:03:50

Oh, re-frame has path middleware for handlers. Cool.

(reg-event-db
  :select-report
  (path [:report-section :selected-report])
  (fn [report]
    (assoc report :id id)))

mikethompson10:03:47

@armed you can even do this (although I'm not sure it is clearer :-)):

(reg-event-db
  :select-report
  (path [:report-section :selected-report :id])
  (fn [_ [_ id]]
    id))

armed10:03:18

@mikethompson yes, but that scares me :)

armed10:03:41

Too cryptic imo

timgilbert17:03:57

What are people's thoughts on whether it's preferable to pass data down to subcomponents as properties vs having the subcomponents subscribe to the appropriate sub-tree of the app-db?

shaun-mahood17:03:46

@timgilbert: My general approach - if the component makes no sense outside of the subscription context, or there are other substantial benefits to subscribing, then I subscribe directly If the component could be reused elsewhere in the app, or there are other benefits to passing things in directly, then I pass in props. Usually I go back and forth a few times between the 2 as I'm iterating on part that I'm not sure of, and it's usually a pretty simple change if I haven't gone too crazy.