Fork me on GitHub
#reagent
<
2017-08-22
>
reefersleep10:08:42

@lexwin I’ve been interested in using the lifecycle functions, too, but so far only managed to figure out how to animate with css (in reagent).

reefersleep10:08:09

I wonder if it’s “just” a question of wrapping a seq of children in a transition-group, and using reagent.core/create-class on each of the children, supplying all of those transition-group-specific lifecycle methods (`:component-will-appear`, component-did-leave and so on) to each of the children

reefersleep10:08:56

But then, I remember having React warn me (via reagent) that create-class was going to be deprecated

lexwin10:08:58

@reefersleep I actually got something to workish yesterday.

reefersleep10:08:11

I’d love to see a gist or project 🙂

lexwin10:08:44

Yes, I did using create-class and read through code and used alot of debugging tools and it seemed like it should have worked but did not. Then like a last thing before I gave up i tried setting properties instead and that seemed to work.

reefersleep10:08:32

I don’t know what you mean when you refer to properties.

lexwin10:08:46

Ye, I will get some code for you.

reefersleep10:08:52

nice :thumbsup:

lexwin10:08:32

(def tg (reagent/adapt-react-class
         js/ReactTransitionGroup.TransitionGroup))

(defn hello []
  (doto (reagent/current-component)
    (aset "componentWillAppear" (fn [cb] (log "appear") (cb)))
    (aset "componentWillEnter" (fn [cb] (log "enter") (cb))))
  [:div "Hello world"])

(defn app []
  [tg
   [hello]])

lexwin10:08:42

Have not investigated this deeply but atleast it prints something and that's infinetely more far than I've got before.

reefersleep10:08:24

what does current-component refer to? hello or tg ?

reefersleep10:08:42

(I guess only hello would be the sensible answer)

lexwin10:08:04

Should be hello, since it's refered to with [

lexwin10:08:26

But if I in app would use ( then I guess it would be tg?

reefersleep10:08:05

That’s interesting in and of itself 😄

reefersleep10:08:15

I haven’t used current-component before

reefersleep10:08:51

here’s my suggestion to do it in a more reagent-ish way:

(def tg (reagent/adapt-react-class
         js/ReactTransitionGroup.TransitionGroup))

(defn hello []
  (reagent.core/create-class 
    {:reagent-render [:div "Hello world"]
     :component-will-appear (fn [cb] (log "appear") (cb))
     :component-will-enter (fn [cb] (log "enter") (cb))
    }
  )
)
(defn app []
  [tg
   [hello]])

reefersleep10:08:19

(trailing parens because I’m editing in slack 😄 )

reefersleep10:08:40

does that make sense?

lexwin10:08:17

Yes, that's the first thing I tried but did not work.

lexwin10:08:34

And I don't know why, when I read the source it seems like it should.

reefersleep10:08:44

maybe create-class prunes off those extra lifecycle functions?

reefersleep10:08:49

yeah… I can’t make sense of that, though. In the documentation I read, it said that the high-level API assigns those lifecycles to the children, so I don’t understand why they are removed

reefersleep10:08:31

but I’m not used to reading js, and definitely not react code.

reefersleep10:08:01

I wonder if any of the re-frame guys have maybe worked with react-transition-group? Can’t remember if I’ve asked in #re-frame already

lexwin10:08:15

I'm gonna investigate if I can use this to acheive what I want (that is chained transitions) and if so I might revisit the code again to see if would be possible to reagentify.

reefersleep11:08:47

Godspeed, good sir 🙂

lexwin11:08:02

I'll come back here if I make some significant discovery 🙂

urbank11:08:47

Hm... so with reactions. If I have a list of components which can either be in view or edit mode.

urbank11:08:33

they all deref a subscription to find out whether they should be edited.

urbank11:08:24

when I just had view they all just received an id and rerendered when the data associated with the id changed

urbank11:08:35

but now they all depend on knowing which id is being edited

urbank11:08:49

so when the id that is being edited changes, they all update

urbank11:08:03

I suppose I'm asking if there's a way to make this more fine grained

urbank11:08:29

to more explicitly decide when to rerender based on current and previous value of reaction

urbank11:08:11

so only rerender if id of row is the same as the edit id

urbank11:08:26

Beginning to think that I would prefer a system where only the mutation of the state decides what needs to be rerendered

reefersleep11:08:05

I wonder how you can desire to avoid re-rendering when depended data changes, though? I’m guessing you have something like :on-change handlers which close over the id, and if they aren’t updated when the id changes, well, you’d call the handler with the wrong argument whenever the id has changed, yeah?

reefersleep11:08:48

I feel like I’m missing some part of your puzzle @urbank , probably because I’m having a hard time visualizing your code context.

urbank12:08:41

@reefersleep Yeah, spitballing a bit 😛 . Also discussing this on #keechma (neat framework on top of reagent by the way. NOT my creation). Well sometimes the data is dependent but its change almost never results in the component actually rendering differently. So let's say you have ~100 components where they each subscribe with a different id. However they also have a joint subscription to just ONE changing id (`edit-id`). Whenever edit-id changes it will result in max 2 actual row changes (the one that is no longer being edited and the one which is the newly edited one), but in fact they will all rerender because they all subscribe to the edit-id which has changed. Optimally a row would only rerender if edit-id is the same as its id or was previously equal to edit-id but is no longer. I hope this is somewhat clear. I see though that this could also be achieved by refactoring the id subscription so that it would return the entity data AND that it is being edited only if it is being edited.

reefersleep12:08:01

can’t you make a subscription like :is-being-edited? that takes an id, and then handle the check in its fn? that way, each of your components are all dependent on that subscription, but the dereffed subscription data only changes for those two components.

reefersleep12:08:10

oh wait, I’m thinking in terms of re-frame

reefersleep12:08:20

but the design still applies

reefersleep12:08:27

I think. 😄

urbank12:08:35

... hm. Haha, you're right of course 😄

reefersleep12:08:10

I hope it holds!

urbank12:08:56

That solves the problem exactly, actually! Thanks! Guess I was stuck in the mindset that the subscriptions returns the edited id.

urbank12:08:21

Damn, seems so clearly like the most elegant solution now. I was optimizing by doing almost exclusively get-in in subscriptions but in this case the computation is actually much better

urbank12:08:37

I think this is one of those moments where I will remember solution when I run into a similar problem and it will help me solve that one. Snapped me out of the no computation in sub is always more optimal. This will cascade further. So yes, much obliged!

reefersleep14:08:57

That’s great 😄 When I first heard about reactions (and subscriptions in re-frame) and about how you could put any amount of computation in there, I imagined long complex, but really, I’ve been using them for relatively simple stuff.

reefersleep14:08:39

Or maybe it seems simple now that I’ve become accustomed to throwing pure core functions around.

reefersleep14:08:50

In any case, I think I underestimated that power to begin with as well 🙂

reefersleep14:08:30

And that must be because there are a lot of “simple” gets and get-ins in subscriptions - this has especially been the case for me in the first phases of building my apps 🙂