Fork me on GitHub
#reagent
<
2016-10-15
>
gadfly36100:10:59

@mathpunk To continue with your example, I would probably write the card like this

(defonce app-state
  (reagent/atom {:expanded? false}))

(defn card [ratom]
  (let [expanded? (:expanded? @ratom)]
    [:div.card
     ... ]))

(defn page [ratom]
  [:div
   [card ratom]
   ])

(reagent/render [page app-state]
                (.getElementById js/document "app"))
Also, I mentioned cursors (similar to Om cursors) because if you use a single atom, you will probably introduce some nesting. An alternative to cursors, is to use re-frame, which is simply awesome.

gadfly36100:10:34

I actually try to avoid using the pattern (get-in @state [:some :path :to :data]) because having to know :some :path :to part I think is exposing too much to the view and will make it harder for you to reorganize your app-state if you decided to do so later.

mathpunk00:10:47

@gadfly361: That is not what I would have expected, passing an atom as an argument. I thought the point was to have it global and have all yr components deref it.

mathpunk00:10:15

I copied the structure of how re-frame suggests app-making, but since I am new to apps at all, I'm not using anything more than reagent

mathpunk00:10:57

really i'm trying to learn HTML and React while minimizing my use of the < > keys

mathpunk00:10:05

so much damn typing in JSX

gadfly36100:10:09

@mathpunk I used to have a global atom that all your components deref directly, but then I read, if i remember correctly, this blog post (http://blog.jenkster.com/2015/12/what-is-functional-programming.html) by @krisajenkins. My take-away was that your functions should have referential transparency and i thought accessing a global var directly was violating that ... it should be passed in as an argument to the function instead. Some of the benefits I have experienced is that testing has become easier, and i don't have to do anything weird, like use iframes, to get devcards to work properly.

gadfly36100:10:57

It should be noted that this is my preference and the community I think is fractured on the issue. There are benefits to both approaches, just depends on the trade-offs you are willing to make.

johanatan01:10:11

@gadfly361 what about (reagent/cursor app-db (concat base [:inner :path :to :data]) where base is passed in and [:inner :path :to :data] is an impl detail of a particular component and thus prime for that encapsulation?

johanatan01:10:53

and yes like you mentioned cursors can be extended when passed in as well

johanatan01:10:49

i.e., pass either base (as a vector of keywords) or a root cursor (which can be extended)

gadfly36101:10:48

@johanatan Yeah, I think that makes sense to me! I have used something similar. I have a cursor called bin, where I store page level stuff