This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-12-28
Channels
- # admin-announcements (72)
- # aws (23)
- # beginners (43)
- # boot (140)
- # cider (11)
- # cljs-dev (4)
- # cljsrn (82)
- # clojars (2)
- # clojure (215)
- # clojure-nl (2)
- # clojure-russia (149)
- # clojurecup (4)
- # clojurescript (159)
- # cursive (19)
- # datomic (47)
- # editors (1)
- # emacs (27)
- # hoplon (32)
- # jobs (11)
- # ldnclj (3)
- # mount (33)
- # off-topic (1)
- # om (380)
- # onyx (1)
- # re-frame (2)
- # reagent (54)
- # yada (63)
@serce: do you mean you have a list of [A B C], and you want to create three reactions: one to A, one to B, one to C, or you want to create three reactions that react to the whole list?
@kauko: I mean i have reaction that react to whole list (reaction to [A, B, C]) and i want to create list of reactions to each item ( [reaction to A, reaction to B, reaction to C])
Hmm, maybe you could use wrap
on each item in the list, and deref that in each reaction?
(let [list-of-reactions (map-indexed (fn [index item] (reagent/wrap #(get @list index) #(swap! list assoc-in index %))))
hi all. What are "reactions" in reagent? Sounds like an intriguing concept, can't find any docs on it anywhere... Something akin to event handlers?
You can look at it as a value derived from some other value, that will be calculated and then cached for as long as any reactive "thing" inside it's body will not change.
You can think of a reaction as a ratom, that changes over time based on it's inputs (ratoms or other reactive things inside the reaction body).
Has a state
mutable field, just like the ratom - https://github.com/reagent-project/reagent/blob/master/src/reagent/ratom.cljs#L337
ok, starting to make sense now... trying to imagine a use case: I could use a reaction to make a computed/derived "view" of the app-state atom - something like that?
(reaction (sort-by :date (:appointments @state)))
would return you a sorted view of your data
and i could use such a view as a basis for a component's state, instead of the component having to do all of the traversal/transformation of the app-state itself...
Though in this case means that if you do for example (swap! state :patients conj new-patient)
this will also trigger re-sorting
In that case you would probably want more granular reactions, like say
(def appointments (reaction (:appointments @state)))
(def sorted-appointments (reaction (sort-by :date @appointments)))
This should make the sorted-appointments
re-sort only when appointments actually changed.
At least that's how I understand the behaviour is. If I'm wrong then please do correct me, don't want to spread misinformation.
i been using devcards to wrap my head around reagent.. makes for a fun learning experience
re-frame wiki has nice articles about reagent internals - https://github.com/Day8/re-frame/wiki
Yeah, it is pretty great. I didn't exactly get it until I re-implemented it by myself, but when you catch on you can appreciate the thought behind it.
IMO something like re-frame but with datascript and relay-like queries as the data layer instead of a single ratom would be awesome.
tighter integration with the server side in the form of relay-something-rather seems like a logical next step, since i bet that 95%+ of apps built with re-frame talk to some remote api and fetch some data