Fork me on GitHub
#reagent
<
2015-12-28
>
kauko07:12:39

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

serce08:12:10

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

kauko08:12:40

Hmm, maybe you could use wrapon each item in the list, and deref that in each reaction?

kauko08:12:18

Though I'm not sure how wrap works since the original list is already a reaction

kauko08:12:50

(let [list-of-reactions (map-indexed (fn [index item] (reagent/wrap #(get @list index) #(swap! list assoc-in index %))))

kauko08:12:07

Something like that? 😮

serce08:12:48

Looks interesting, thanks, i will look into it.

kauko08:12:54

wrap returns atoms though, not reactions

kauko08:12:01

So maybe that's not what you want

peterbak15:12:34

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?

jaen15:12:29

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.

peterbak15:12:50

cached in the same atom at some other path?

jaen15:12:41

Internally to a reaction.

jaen15:12:11

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

peterbak15:12:22

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?

jaen15:12:47

For example

jaen15:12:41

(reaction (sort-by :date (:appointments @state))) would return you a sorted view of your data

jaen15:12:52

That's re-sorted only if @state changes.

peterbak15:12:18

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

jaen15:12:01

Though in this case means that if you do for example (swap! state :patients conj new-patient) this will also trigger re-sorting

jaen15:12:05

Since this ratom changed.

jaen15:12:55

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)))

jaen15:12:19

This should make the sorted-appointments re-sort only when appointments actually changed.

jaen15:12:48

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.

jaen15:12:11

@peterbak: if you take a look at re-frame it's the basic conceit behind it

jaen15:12:18

There are subscriptions which create reactions

jaen15:12:31

And you base your components on those subscriptions.

peterbak15:12:04

thanks a lot @jaen, I get it now simple_smile

jaen15:12:10

No problem. Hopefully I didn't get too much wrong xD

jaen15:12:38

Feel free to play around with that by yourself so you can get a hang of it.

peterbak15:12:11

i been using devcards to wrap my head around reagent.. makes for a fun learning experience

jaen15:12:13

re-frame wiki has nice articles about reagent internals - https://github.com/Day8/re-frame/wiki

jaen15:12:22

Basically a must read.

peterbak15:12:29

ok, will read

jaen15:12:54

Especially the one on difference between reagent component form types.

peterbak15:12:53

functions-returning-hiccup vs higher-order functions vs create-class something?

peterbak15:12:48

anyway, reading through re-frame docs now

jaen15:12:19

Yep, that.

jaen15:12:32

If you have a handle on it already then it's probably less helpful

jaen15:12:40

But documents the differences and gotchas really nicely.

peterbak16:12:05

the clarity of ideas in re-frame is blowing my mind

jaen17:12:31

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.

jaen17:12:34

IMO something like re-frame but with datascript and relay-like queries as the data layer instead of a single ratom would be awesome.

peterbak17:12:22

...so, something like om.next but simpler simple_smile

peterbak17:12:59

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

jaen17:12:52

Yeah, something like om.next just with a reagent view.

peterbak18:12:30

anybody else ran into the following error with re-frame: ANALYSIS ERROR: Referred var reagent.impl.batching/do-later does not exist on file null, line null, column null looks like a jar version mismatch between reagent and re-frame?

peterbak18:12:04

argh, looks like figwheel cached something somewhere. Running 'lein cljsbuild once' fixed it. weird.