This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-23
Channels
- # announcements (5)
- # beginners (14)
- # bigdata (1)
- # calva (13)
- # cider (10)
- # clj-kondo (53)
- # cljs-dev (1)
- # cljsrn (12)
- # clojure (67)
- # clojure-uk (8)
- # clojuredesign-podcast (3)
- # clojurescript (53)
- # duct (4)
- # emacs (1)
- # events (1)
- # figwheel-main (5)
- # fulcro (9)
- # graalvm (68)
- # graphql (3)
- # joker (3)
- # juxt (4)
- # off-topic (32)
- # other-languages (1)
- # pathom (35)
- # re-frame (6)
- # rum (1)
- # shadow-cljs (52)
- # spacemacs (3)
- # sql (10)
- # tools-deps (15)
Hello! Does (def x)
actually do anything, aka does it get translated to a line of code in Javascript?
so after some testing… (def x)
definitely does something. After all, if you do (def x) (def x),
the compiler complains that x
is being redefined. I was trying to figure out a variable’s namespace using resolve
and when I saw that (def x) (resolve 'x)
returned nil, I was puzzled. But probably a better way of getting a variable’s namespace is doing (:ns (meta #'x))
, and using that technique definitely returns the namespace of x
even if it is defined using (def x)
i.e. without an initial value.
that information gets stored in the cljs analyzer, but it looks like CLJS doesn't by default emit any JS for just (def x)
ok, got it, thanks!
Prefer emotion over cljss, it doesn't really get you anything. Cljss is gonna adopt emotion at some point
would it be possible to create a Clojure namespace and intern a var at macroexpansion?
(ns my-app.core
(:require [hx.core :as hx :refer [defnc]])
(defnc MyComponent []
(d/div "foo"))
Would create MyComponent
in the CLJS namespace, and potentially create a Clojure namespace my-app.core
and intern a macro like:
(defmacro my-component []
`(create-element MyComponent))
so that the macro would be available within the namespace and to consumers who require
itfor that to work the user would need to have (:require-macros [app.core])
in app.core
yeah, and it's in a weird state because the macroexpansion would have to happen before resolving the macro ns which is... not how it works
I thought you are creating function components? why not defnc my-component
emitting a (defn my-component
?
the components are defined as functions, but you don't want to call them as functions. you need to create a React element from them
I'm playing with getting rid of hiccup syntax and using factory functions or create-element directly
no matter what I try, I feel like I concede either interop, performance or ergonomics. I hate hiccup but going back to factory functions maybe isn't really better?
one thing I experimented with was a macro emitting a my-component
defn which would be the factory fn. it would then emit a secondary "hidden" function that you could get to when needed by calling @my-component
yeah, the way I do factory functions right now is it specifies a custom protocol that does something similar
(hx/type my-component) ;; => the actual Component type (class/function)
if I use a factory function, then the props that get passed: creates a map, turns it into a JS object, then React takes that JS object and copies when it creates the element...
I have a macro that, when used, will always emit a JS object instead of creating a map. but it's tedious to create factory macros in a separate file
mine would do (defn my-component [props] (react/createElement my-component* #js {:secret$props props}))
and the component would access that secret$props
. never actually translating to JS object
that works, except when you are working with: 1. native elements 2. a lib that expects to be passed Component
native components don't ever go through those factory functions so thats not a problem
let me see if I can find that code somewhere ... I'm sure its in some branch somewhere
can't find it but note that I opted out of that approach because it generated too much code