Fork me on GitHub
#reagent
<
2017-01-31
>
vikeri13:01:40

Can I define static class methods/attributes easily in reagent? r/create-class creates normal instantiated methods but to add a static method I had to do this, which is a little ugly (to say the least):

(def app-root-comp (let [comp (r/reactify-component app-root)]
                     (aset comp "navigationOptions" #js {"title" "Welcome"})
                     comp))

pesterhazy14:01:43

@vikeri why would you want that?

pesterhazy14:01:40

Maybe it's easiest to create a non-reagent component by calling React.createClass directly?

pesterhazy14:01:29

not sure how to add static variables to those though

vikeri14:01:42

That would need the same aset. r/create-class is using React.createClass under the hood.

pesterhazy14:01:00

are they seriously phasing out ES5 now?

pesterhazy14:01:10

that seems unwise

pesterhazy14:01:25

ES5 is the greatest common denominator

vikeri14:01:44

No, in plain js it’s no big deal to do myClass.title = “hello”

vikeri14:01:08

So assigning static attributes is not an issue for ES5

pesterhazy14:01:41

how do you subclass React.Component in ES5 though?

pesterhazy14:01:00

(my ES6 is rusty, sorry if I'm being slow)

vikeri14:01:59

My OO is probably rusty 😝

pesterhazy14:01:14

class HomeScreen extends React.Component

pesterhazy14:01:25

from the example you linked

vikeri14:01:50

You just use React.createClass that yields the same result

pesterhazy14:01:48

yeah I guess (set! ...) is an okay approach then?

pesterhazy14:01:20

you can use doto to clean up the snippet you posted

pesterhazy14:01:38

but other than that it seems pretty good.. you could make a wrapper-fn with-static-vars?

vikeri15:01:28

@pesterhazy Yeah in the end I did a wrapper function

pesterhazy15:01:09

@vikeri could you share the wrapper? In case it comes up

pesterhazy15:01:30

Might also be a possible addition as a "mixin" for https://github.com/pesterhazy/recalcitrant

vikeri15:01:25

I’m working on updating https://github.com/vikeri/re-navigate so the code will be there.

vikeri15:01:43

It’s specific to navigation so not a general wrapper in that sense

pesterhazy15:01:41

haven't seen other react components rely on static class properties yet