Fork me on GitHub

@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)]
     ... ]))

(defn page [ratom]
   [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.


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.


@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.


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


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


so much damn typing in JSX


@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 ( 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.


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.


@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?


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


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


@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