i'm trying to generate helix native components but the JS ones are nested inside an object.
i.e. c.View
, c.Text
how would I go about accessing an object's property inside a macro?
i've tried this:
(defn- gen-comp
[v]
`(defmacro ~v [& args#]
`(hx/$ ^:native (.-~v c)
~@args#)))
but shadow-cljs returning No such var: rf.core.comps/v
the double quoting makes it weird
you have to double unquote ~
it to get the value of v
try
(defn- gen-comp
[v]
`(defmacro ~v [& args#]
`(hx/$ ^:native (.-~~v c)
~@args#)))
interesting, wasn't aware of double quoting new error:
Encountered error when macroexpanding helix.core/$.
[1] Error in phase :compilation
[1] dot prop access with args
so looks like accessing the v
variable works now, but the object access isn't possible for some reason?
hm, the error doesn’t make much sense to me
if you’re using the code I pasted above
I’m not sure you can splice into dot property access like that
might be best to use goog.object/get
maybe try (goog.object/get c v)
getting this right is super hard though, might be easier to do without macros, or at least not by generating macros.
if there’s only a few properties
yea that might be the issue, will try using goog.object
what exactly does ~~
do btw? can't find info about it online
I guess ~
is unquote, but if the thing you unquote is still quoted, you can do another ~
to unquote again
yeah, your macro used ` twice
(let [v 'Foo]
v)
;; => Foo
(let [v 'Foo]
`v)
;; => v
(let [v 'Foo]
`~v)
;; => Foo
(let [v 'Foo]
``~v)
;; => v
(let [v 'Foo]
``~~v)
;; => Foo
the error sounds like you are trying to do (.-~~v c foo bar)
which won’t work
the dot prop access with args
no just (.-~~v c)
, and looks like (o/get c ~~v)
gives same error. but going to try again in a bit
the other problem that I was thinking of was that the c
might not be available
the macro will literally expand to ($ (.-v c) …)
inside whatever namespace you use it in
so you need to make sure that c
is required in that namespace
wait no, nevermind
Yea it’s required, code works when I hand write each macro
it should auto-namespace c
because it’s in a syntax quote…
can you paste the full error?
Encountered error when macroexpanding helix.core/$.
[1] Error in phase :compilation
[1] dot prop access with args
[1] {:form (. #function[rf.core.comps/vw] - rf.core.comps/c)}
[1] ExceptionInfo: dot prop access with args
[1] shadow.build.cljs-hacks/shadow-analyze-dot (cljs_hacks.cljc:483)
[1] shadow.build.cljs-hacks/shadow-analyze-dot (cljs_hacks.cljc:438)
[1] shadow.build.cljs-hacks/eval10376/fn--10378 (cljs_hacks.cljc:510)
[1] clojure.lang.MultiFn.invoke (MultiFn.java:252)
[1] cljs.analyzer/analyze-seq* (analyzer.cljc:3934)
[1] cljs.analyzer/analyze-seq* (analyzer.cljc:3932)
[1] cljs.analyzer/analyze-seq*-wrap (analyzer.cljc:3939)
[1] cljs.analyzer/analyze-seq*-wrap (analyzer.cljc:3937)
[1] cljs.analyzer/analyze-seq (analyzer.cljc:3963)
[1] cljs.analyzer/analyze-seq (analyzer.cljc:3941)
[1] cljs.analyzer/analyze-form (analyzer.cljc:4150)
[1] cljs.analyzer/analyze-form (analyzer.cljc:4147)
[1] cljs.analyzer/analyze* (analyzer.cljc:4200)
[1] cljs.analyzer/analyze* (analyzer.cljc:4191)
[1] cljs.analyzer/analyze (analyzer.cljc:4220)
[1] cljs.analyzer/analyze (analyzer.cljc:4203)
[1] cljs.analyzer/analyze-seq (analyzer.cljc:3964)
[1] cljs.analyzer/analyze-seq (analyzer.cljc:3941)
[1] cljs.analyzer/analyze-form (analyzer.cljc:4150)
[1] cljs.analyzer/analyze-form (analyzer.cljc:4147)
[1] cljs.analyzer/analyze* (analyzer.cljc:4200)
[1] cljs.analyzer/analyze* (analyzer.cljc:4191)
[1] cljs.analyzer/analyze (analyzer.cljc:4220)
[1] cljs.analyzer/analyze (analyzer.cljc:4203)
[1] cljs.analyzer.api/analyze (api.cljc:88)
[1] cljs.analyzer.api/analyze (api.cljc:69)
[1] cljs.analyzer.api/analyze (api.cljc:80)
[1] cljs.analyzer.api/analyze (api.cljc:69)
[1] cljs.analyzer.api/analyze (api.cljc:78)
[1] cljs.analyzer.api/analyze (api.cljc:69)
[1] cljs.analyzer.api/analyze (api.cljc:77)
[1] cljs.analyzer.api/analyze (api.cljc:69)
[1] helix.impl.analyzer/inferred-type/fn--38888 (analyzer.clj:80)
[1] helix.impl.analyzer/inferred-type (analyzer.clj:80)
[1] helix.impl.analyzer/inferred-type (analyzer.clj:79)
[1] helix.core// (core.clj:22)
[1] helix.core// (core.clj:7)
[1] clojure.core/apply (core.clj:669)
[1] clojure.core/apply (core.clj:660)
[1] cljs.analyzer/macroexpand-1*/fn--2556 (analyzer.cljc:3879)
[1] cljs.analyzer/macroexpand-1* (analyzer.cljc:3877)
[1] cljs.analyzer/macroexpand-1* (analyzer.cljc:3864)
[1] cljs.analyzer/macroexpand-1 (analyzer.cljc:3928)
[1] cljs.analyzer/macroexpand-1 (analyzer.cljc:3924)
[1] cljs.analyzer/analyze-seq (analyzer.cljc:3961)
[1] cljs.analyzer/analyze-seq (analyzer.cljc:3941)
[1] cljs.analyzer/analyze-form (analyzer.cljc:4150)
[1] cljs.analyzer/analyze-form (analyzer.cljc:4147)
[1] cljs.analyzer/analyze* (analyzer.cljc:4200)
[1] cljs.analyzer/analyze* (analyzer.cljc:4191)
[1] cljs.analyzer/analyze (analyzer.cljc:4220)
[1] cljs.analyzer/analyze (analyzer.cljc:4203)
[1] cljs.analyzer/analyze-seq (analyzer.cljc:3964)
[1] cljs.analyzer/analyze-seq (analyzer.cljc:3941)
[1] cljs.analyzer/analyze-form (analyzer.cljc:4150)
[1] cljs.analyzer/analyze-form (analyzer.cljc:4147)
[1] cljs.analyzer/analyze* (analyzer.cljc:4200)
[1] cljs.analyzer/analyze* (analyzer.cljc:4191)
[1] cljs.analyzer/analyze (analyzer.cljc:4220)
[1] cljs.analyzer/analyze (analyzer.cljc:4203)
[1] cljs.analyzer/analyze (analyzer.cljc:4213)
[1] cljs.analyzer/analyze (analyzer.cljc:4203)
[1] cljs.analyzer/analyze (analyzer.cljc:4211)
[1] cljs.analyzer/analyze (analyzer.cljc:4203)
[1] cljs.analyzer/fn--1962 (analyzer.cljc:2262)
[1] cljs.analyzer/fn--1962 (analyzer.cljc:2248)
[1] clojure.lang.MultiFn.invoke (MultiFn.java:252)
[1] cljs.analyzer/analyze-seq* (analyzer.cljc:3934)
[1] cljs.analyzer/analyze-seq* (analyzer.cljc:3932)
[1] cljs.analyzer/analyze-seq*-wrap (analyzer.cljc:3939)
[1] cljs.analyzer/analyze-seq*-wrap (analyzer.cljc:3937)
[1] cljs.analyzer/analyze-seq (analyzer.cljc:3963)
[1] cljs.analyzer/analyze-seq (analyzer.cljc:3941)
[1] cljs.analyzer/analyze-form (analyzer.cljc:4150)
[1] cljs.analyzer/analyze-form (analyzer.cljc:4147)
[1] cljs.analyzer/analyze* (analyzer.cljc:4200)
[1] cljs.analyzer/analyze* (analyzer.cljc:4191)
[1] cljs.analyzer/analyze (analyzer.cljc:4220)
[1] cljs.analyzer/analyze (analyzer.cljc:4203)
[1] cljs.analyzer/analyze (analyzer.cljc:4213)
[1]
and you get the same error with gobj/get
?
actually, no, after restarting shadow-cljs i'm seeing Can't take value of a macro: #'rf.core.comps/vw
error
will have to look into that when i have more time later today