This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-10-15
Channels
- # beginners (11)
- # boot (80)
- # carry (1)
- # cider (5)
- # cljs-dev (290)
- # cljsrn (4)
- # clojure (50)
- # clojure-canada (5)
- # clojure-dev (2)
- # clojure-korea (2)
- # clojure-russia (17)
- # clojure-spec (22)
- # clojurescript (41)
- # cursive (12)
- # datomic (10)
- # figwheel (1)
- # hoplon (68)
- # klipse (1)
- # off-topic (1)
- # om (16)
- # onyx (15)
- # parinfer (1)
- # proto-repl (4)
- # proton (2)
- # re-frame (14)
- # reagent (12)
- # ring (5)
- # vim (4)
- # yada (34)
@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.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
@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.
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?
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