This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-30
Channels
- # announcements (15)
- # beginners (99)
- # boot (15)
- # cider (105)
- # cljdoc (2)
- # cljs-dev (17)
- # clojure (132)
- # clojure-conj (1)
- # clojure-dev (5)
- # clojure-italy (19)
- # clojure-losangeles (2)
- # clojure-nl (20)
- # clojure-spec (70)
- # clojure-uk (50)
- # clojurescript (153)
- # core-logic (9)
- # cryogen (4)
- # cursive (6)
- # datomic (40)
- # duct (5)
- # figwheel-main (10)
- # fulcro (245)
- # hoplon (1)
- # jobs (3)
- # leiningen (12)
- # mount (8)
- # nrepl (11)
- # off-topic (1)
- # pathom (16)
- # pedestal (3)
- # planck (17)
- # re-frame (3)
- # reitit (8)
- # shadow-cljs (64)
- # spacemacs (3)
- # specter (20)
- # tools-deps (21)
@aron probably just a bug, the REPL we ship still needs a lot of work - but it doesn't get a ton of love since it mostly used for testing + Quick Start - other REPLs like Figwheel will probably have whatever config you need to do what you want
Hi all, Iām trying to resolve this warning Iām getting on build:
Oct 30, 2018 1:42:17 PM com.google.javascript.jscomp.LoggerErrorManager println
WARNING: resources/public/generated/js/inferred_externs.js:109: WARNING - name goog is not defined in the externs.
goog.string.StringBuffer;
^^^^
youād have to quote everything if you used sexps, no? I always assumed thatās why vectors were preferred. (maybe thatās not what youāre talking about?)
(defn factory [el]
(fn [& args] (apply react/createElement el args)))
(def div (factory "div"))
(def MyComponent
(factory (fn [props]
(div "Hello!"))))
I guess Iād rather pass a vector and let factory sort it out rather than introduce a macro whose only purpose is to avoid quoting
I'm looking at removing the need of controlling the render tree in CLJS-land. so we should be just using regular ol' react components (functions or classes) that return react elements
in order to use hiccup, we have to use a macro to convert [:div "blah"]
to (react/createElement "div" nil "blah")
defining components already needs some macro-ness to remove the boilerplate for converting props into clojure maps
so it's easy to also add, "create the factory for this component" to the macro anyway
on a current project the benefit is itās way easier to interact/debug hiccup then React stuff
then you can share templates, and rendering hiccup serverside is a middleware-ish thing
thatās how a current client project Iām working on is set up and itās simple and gets the job done
in Om I opted for fn calls - due to thinking about perf - but from what Iāve seen over the past almost 5 years
and just implementing precise reconciliation will blow away any other perf stuff you could think about
to me Hiccup is a local maxima - youāre unlikely to come up with something better thatās as easy to work with
the #1 thing for me is that any "component" is just a React component. not a special CLJS-only thing
I suppose if perf is not important you could parse the hiccup in the render function?
thought: offer a macro if the hiccup is really static and then just opt in if you need it (?). i just happen to work in an environment where this kind of overhead is never the performance bottleneck
my experiments are all in https://github.com/Lokeh/hx right now. currently, it's very macro heavy
hx.react/c
is the hiccup compiler macro. I could move that to runtime and it would probably simplify things
I also suspect with transducers the performance hit wonāt be that meaningful client-side
I think that having a macro for defining components will still be needed. marshaling props into CLJS data structures is not fun
it's not specific to react hooks, but react components in general.
(defn my-component [props] ;; <-- props is a JS object
(let [name (goog.object/get props "name")]
[:div "Hello, " name "!"]))
I would prefer to shallowly convert it to a CLJS map so that it could be destructured, etc.
same thing for passing in props to components. you can't pass in just a map to a React component as props because it introspects & manipulates the props and expects it to be a normal JS object
yeah thats my concern about hooks as well. the inputsAreEqual
function that checks the extra inputs
argument doesn't support CLJS equality semantics which may be annoying to work around
@lilactown hrm when do they introspect props? So hooks does or doesnāt support plain old fns?
(sorry I really donāt know, I didnāt see anything like this when I looked at what they wrote up)
(defn example [props]
(react/createElement "div" nil (prn-str props)))
;; rendering:
(react/createElement example {:name "Suzy"} "asdf")
output on screen:
#js {:meta nil, :cnt 1, :arr #js [:name "Suzy"], :__hash nil, "cljs$lang$protocol_mask$partition0$" 16647951, "cljs$lang$protocol_mask$partition1$" 139268, :children "asdf"}
react/createElement
copies the object but you can just create the element object directly instead which skips that copy
https://github.com/facebook/react/blob/master/packages/react/src/ReactElement.js#L112-L124
although I'm no longer sure about the owner
thing. it used to be deprecated, might not be anymore
@lilactown but does React actually need that children
?
I think there are many times when people want to use the children
prop š
unless Iām missing your point
are you saying that you donāt see the point of being able to render an element passed in as a prop? or that you just donāt use Reactās children
prop to do that?
the former I canāt agree with. we do that a ton at work to share styling and logic
I donāt see why you cannot set up the transformations when you need them - if theyāre required
I want to do this:
(defn example-2 [{:keys [name children]}]
(into
[:div
[:div "Hello, " name "!"]]
children)
(defn app [_]
[example-2 {:name "Uma"} [:div "I'm a child"]])
itās worth looking around at how people actually use Reagent or even Om Next, we donāt pass around children
the point is that I want to be able to read props and pass in props to any React component just like in JS
Iām just saying I donāt know why you need to carry over the children
pattern thing
my point is that it still requires some special marshaling of the props received by the function before we can destructure it like that
(defmacro defnc [name props-bindings & body]
`(defn ~name [props#]
(let [~@props-bindings (hx.react/props->clj props#)]
~@body)))
I guess, ultimately, Iām trying to maximize the ability to interop with the React ecosystem. I expect that the props#
will be a normal JS obj. so I could e.g. pass this in to a HOC I installed from npm
likewise when I write [MyComponent {:foo "bar"}]
, MyComponent could be a React component written by me in CLJS or one I installed from npm and I donāt have to care
(unless of course you want to limit the audience to CLJS bootstrapped or something like that)
Iām thinking of it from the perspective of a CLJS user trying to consume JS components. adopting JS semantics I think greatly helps with the frustration I have had with reagent
the React ecosystem has components, frameworks, new features, devtooling, etc. that I could be leveraging but thereās friction due to too many things that are āCLJ-firstā
probably the only suggestion I would say would be to think about separating the couple of useful parts you will need to build
i.e. the fast runtime walker that converts hiccup -> React components - which is generally useful
in the implementation you were talking about before, do you walk the whole tree? or just the body of a component?
since that opens the door for someone who wants to do a reconciler with precise updates
React hooks definitely opens the door to doing a lot of stuff in a more lightweight way for ClojureScript
@lilactown out of curiosity, what react tooling and libraries do you find you can't do without, and which are frustrating to integrate with reagent? I ask because I've yet to start my first non-toy reagent project to get a feel for the real-world work experience with it, so I'm curious about the pitfalls, as so far I like the feel of it better than react itself
clojure.spec.test.alpha/check gives me back a seq of map with keys:
(:spec :clojure.spec.test.check/ret :sym)
is this planned for clojurescript as well? Iād like to see if my num-tests
argument propagated correctly (which does not seems to work in planck).
@borkdude We recently ported all of the Clojure spec changes to ClojureScript, so it may be worth checking to see if master has that new behavior
For reacters here, would you consider the Redux store a kind of an atom? Or agent? Or something else?
itās very similar to an atom. the difference is that your app automatically re-renders when itās changed, and you (usually) dispatch a named action instead of a direct state manipulation