Fork me on GitHub
#reagent
<
2016-04-24
>
pbaille09:04:46

Hi! how can i get/swap the implementation of a particular lifecycle method of a reagent component?

pbaille09:04:48

I’m trying to implement a function named « resizable » that takes a callback (to call on resize event) and a component (hiccup vector) and add the event initialization to the component-did-mount method of the given component

pbaille09:04:16

for Rum users, is there a way to do the mixin stuff that Rum do?

Stefan Roex09:04:25

@pbaille: I’m not sure what you’re trying to achieve. Is it possible to listen to component-will-receive-props and unbind and rebind the on-resize event when the callback changes?

pbaille09:04:43

I don’t want to rebind on each props changes, just on component-did-mount

pbaille09:04:17

I know that I could in each component definition, add it manually but I would like an abstraction if possible

pbaille09:04:49

in a more abstract way, I would like to be able to compose lifecycle methods of an existing component

Stefan Roex09:04:15

What’s your use case?

pbaille09:04:33

my resizable abstraction is an illustration

pbaille09:04:42

be able to kind of do a (merge-with comp ‘lifecycle-methods-map ‘another-method-map)

pbaille09:04:57

do you see what I mean?

Stefan Roex09:04:44

I see, but its mainly syntactic sugar on top of defining reagent/create-class, isn’t it?

Stefan Roex09:04:16

When you define the lifecycle methods as standalone functions, you can easily call comp on them.

pbaille09:04:22

the thing is that I want to do the comp stuff after the component definition

pbaille09:04:04

by the way comp is not the good merge-with function

pbaille10:04:35

if there is a way to access/set component lifecycle methods of an already defined component it should be possible to do what I want

Stefan Roex10:04:16

You’ll probably know this, but could call with-meta on the component, I’m not sure that works at runtime.

Stefan Roex10:04:16

Don’t know how to do it otherwise. I’m not 100% sure what the usecase could be, I’ve been using React the last 2 years and never needed anything like this.

pbaille10:04:10

ok maybe it is useless, but what get me on this way is the way that the « rum » library works, do you know it?

Stefan Roex10:04:56

Rum doesn’t allow this either, does it? You component definition all happens at compile time (just like with-meta) in a macro.

pbaille10:04:03

If I’ve understood well , rum introduce the idea of mixins that allow that kind of lifecycle-methods composition

pbaille10:04:58

wich is pretty powerful I think

Stefan Roex10:04:20

But that all happens at compile time. It isn’t any different than Reagent allows you to do. Or I’m missing a big insight in how Rum works simple_smile. Do you have a link where this behavior of rum is explained?

pbaille10:04:47

I think I’m beginig to getting it

pbaille10:04:18

it is just syntactic sugar you were right I think

pbaille10:04:05

thank you simple_smile I know how to do my stuff now