This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-31
Channels
- # architecture (5)
- # beginners (35)
- # boot (150)
- # cider (1)
- # clara (7)
- # cljs-dev (131)
- # cljsrn (10)
- # clojure (76)
- # clojure-austin (3)
- # clojure-berlin (1)
- # clojure-brasil (1)
- # clojure-chicago (2)
- # clojure-dusseldorf (1)
- # clojure-italy (30)
- # clojure-nl (2)
- # clojure-russia (40)
- # clojure-serbia (2)
- # clojure-spec (25)
- # clojure-uk (13)
- # clojured (2)
- # clojurescript (106)
- # core-async (29)
- # datascript (65)
- # datomic (38)
- # emacs (8)
- # funcool (8)
- # hoplon (6)
- # jobs (3)
- # klipse (93)
- # luminus (16)
- # lumo (4)
- # off-topic (2)
- # om (11)
- # onyx (13)
- # pedestal (4)
- # protorepl (3)
- # re-frame (40)
- # reagent (31)
- # ring (6)
- # ring-swagger (4)
- # slack-help (5)
- # spacemacs (13)
- # untangled (17)
- # vim (2)
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))
Here’s how static attributes on classes work btw: https://babeljs.io/repl/#?babili=false&evaluate=true&lineWrap=false&presets=es2015%2Creact%2Cstage-2&code=class%20klass%20%7B%0A%20%20static%20hejsan%3D%20%22Svejsan%22%0A%7D
@vikeri why would you want that?
@pesterhazy Working on the new React (Native) Navigation: https://github.com/react-community/react-navigation/blob/master/docs/guides/Guide-Intro.md#introducing-stack-navigator
I see!
Maybe it's easiest to create a non-reagent component by calling React.createClass
directly?
not sure how to add static variables to those though
That would need the same aset
. r/create-class
is using React.createClass
under the hood.
are they seriously phasing out ES5 now?
that seems unwise
ES5 is the greatest common denominator
how do you subclass React.Component in ES5 though?
(my ES6 is rusty, sorry if I'm being slow)
class HomeScreen extends React.Component
from the example you linked
I see
yeah I guess (set! ...)
is an okay approach then?
you can use doto
to clean up the snippet you posted
but other than that it seems pretty good.. you could make a wrapper-fn with-static-vars
?
@pesterhazy Yeah in the end I did a wrapper function
@vikeri could you share the wrapper? In case it comes up
Might also be a possible addition as a "mixin" for https://github.com/pesterhazy/recalcitrant
I’m working on updating https://github.com/vikeri/re-navigate so the code will be there.
I see
haven't seen other react components rely on static class properties yet