Fork me on GitHub
#reagent
<
2018-05-14
>
bupkis07:05:41

@fj.abanses - thanks, I'll take a look

Hukka13:05:26

I'm trying to understand how reagent actually works. Why do the binding of this, and then rebinding it both to the js this value ant the first argument via .cal at https://github.com/reagent-project/reagent/blob/master/src/reagent/impl/component.cljs#L179? Wouldn't it be simpler to just do (f c)

justinlee15:05:42

@tomi.hukkalainen_slac there are many mysteries I don’t understand about reagent, but I think what this code does is insert this as the first argument when calling the lifecycle methods. so when you build a form-3 component, the componentWillUpdate method will take this as the first argument so that you have access to the underlying react object

Hukka15:05:09

Yes, but I was thinking that you could also do that with a simple call of (f c rest). Now it seems like it wants to call a javascript function, and make sure that the this is the first parameter but also the javascript this (however you call it), but that's weird. Why would reagent components have javascript lifecycle methods?

Hukka15:05:51

They cannot be usual react lifecycle methods exactly because the first parameter has been added, so then you'd call it like (.call f c rest), without doubling the c

justinlee15:05:30

that’s true. it is probably redundant to bind the interior function and pass it. i’m trying to think if there are compatibility reasons why it would be surprising if the interior lifecycle function’s this was bound to a different object (i.e. if you call helper functions or something).

justinlee15:05:43

ah. here’s why

Call component functions with this set to current component

This makes us more consistent with React classes, and gives more
informative stack traces sometimes.

Also stop wrapping unknown methods - let React deal with them directly.

👍 4
justinlee15:05:53

it used to be (f c rest) until that change

tianshu17:05:45

is there anyone think that in hiccup, one space for indentation make it's hard to read the structure?

mikerod17:05:08

@doglooksgood yeah, I think so too. I typically put newlines more often between hiccup levels when I can’t see it

mikerod17:05:16

However, I don’t know that I think that is the greatest style

tianshu17:05:12

i think a hiccup more than 20 lines is really hard to read.

tianshu17:05:36

i wonder how people solve this problem

mikerod17:05:53

One thing I do pretty often is to extract chunks of hiccup into a separate component

mikerod17:05:19

I think that makes it perhaps more readable anyways in some of the cases where you’d have a a lot of lines of hiccup.

👍 4
tianshu17:05:39

maybe this is the only way

Hukka18:05:39

@lee.justin.m Good catch, thanks

Hukka18:05:26

Another thing I've been wondering is why use state/set-state at all? I have inherited a project where that's done and had to read the source to see what it does (and then more related code elsewhere...) since it's not mentioned anywhere in any docs, nor does there seem to be a single 3rd party guide or tutorial that would use them. Everywhere the state is done with a direct call to ratom bound with lexical scope

justinlee19:05:06

there’s no good reason i can think of to use react’s state mechanism

Hukka19:05:32

It's not react's state, actually

Hukka19:05:05

My coworker mentioned that, but based on the source it's just a "random" field created on the JS object, called cljsField

Hukka19:05:43

It's not used anywhere else, despite the pretty generic name. And it's distinct from the state field that react itself uses

Hukka19:05:29

But instead of being in lexical scope, you can deref it via the JS object. Which doesn't seem to be around except in those lifecycle methods I first asked about (that this)

Hukka19:05:48

Both that and the ratom have seemed to exist for a pretty long time (though the state didn't use ratom internally until 0.4.0), so it doesn't seem to be a case of older idea being superseded with a better one

justinlee19:05:27

yea i don’t know. i did find this comment which may or may not be part of it https://github.com/reagent-project/reagent/issues/47#issuecomment-67303990