Fork me on GitHub
#shadow-cljs
<
2018-05-20
>
emccue06:05:49

I wonder if there is value in making something like this for shadow and clojure

theeternalpulse07:05:15

I defined a macro in a clj file and am using :require-macros to use it in a cljs file but I'm getting a build failure

22 |      ^{:key letter} [letter-button letter])
  23 |    "Now in the drum-kit-lesson"])
  24 | 
  25 | (create-lesson letters)
-------^------------------------------------------------------------------------
ClassCastException: clojure.lang.Cons cannot be cast to clojure.lang.Named
	clojure.core/namespace (core.clj:1589)
	clojure.core/namespace (core.clj:1589)
	cljs.analyzer/fn--1733 (analyzer.cljc:1491)
	cljs.analyzer/fn--1733 (analyzer.cljc:1473)
	clojure.lang.MultiFn.invoke (MultiFn.java:251)
	cljs.analyzer/analyze-seq* (analyzer.cljc:3348)
	cljs.analyzer/analyze-seq* (analyzer.cljc:3346)
	cljs.analyzer/analyze-seq*-wrap (analyzer.cljc:3353)

--------------------------------------------------------------------------------

thheller08:05:38

@theeternalpulse looks like a macro error, probably generating invalid code

theeternalpulse15:05:53

this is my macro. I've reduced it down quit a bit to test and was still getting the error

(defmacro create-lesson [component]
  `(def 'lesson (if style
                  (with-meta `'~component {:style style})
                  `'~component)))

theeternalpulse15:05:32

I'm basically trying to create a def in a namespace that attaches style metadata so when the component is mounted with reagent it also mounts a style tag to the header

thheller18:05:20

yeah that macro is invalid. can't even figure out what it is supposed to do?

thheller18:05:35

but it does not like the 'lesson. that is the error you are seeing.

theeternalpulse19:05:29

I see. I wanted to create a local def called lesson where the macro is used, and not have it try to resolve a namspace.

thheller19:05:30

(def ~'lesson ...) should do that

thheller19:05:10

but you should read about macro hygiene. this is generally not a good idea.

theeternalpulse19:05:07

I am really jsut trying to attach metadata to a clojurescript function but I was reading and in order to fetch it I have to get a reference to thee var, which I can't do in clojurescript

theeternalpulse19:05:55

so I just wanted to create a simple thing that would do (def lesson (with-meta fn {:style style})) if the style var was defined

theeternalpulse19:05:12

I guess it's overkill but it piqued my curiosity and led me down that dark path

thheller19:05:14

I always recommend writing the code entirely without macro (if possible) until it works and then eliminate the boilerplate later

thheller19:05:21

starting with a macro first is always challenging

thheller19:05:49

vars are totally possible though. dynamic vars are not.

theeternalpulse19:05:52

yeah, it's a bit harder to debug in clojurescript

theeternalpulse19:05:04

even with cider connected, doesn't seem to like macros

thheller19:05:22

its tricky since macros are written in clojure

theeternalpulse19:05:20

yeah, Either way, that cleared it up. I'll go down the easier path, too much of a rabbit hole to be worth it lol

thheller08:05:14

@kenny please open an issue so I don't forgot. the error should be more clear indeed.

wilkerlucio21:05:57

@thheller noticed something weird here, I just add my test folder to my source-paths, and for some reason, now on my chrome compilations I'm getting start code from fulcro-spec, which doesn't make sense, on my chrome entry points there is nothing pointing to fulcro-spec, and this start code from spec is messing up other things, just removing the test from :source-paths and recompiling fixes it, any idea what that might be?

thheller21:05:25

what is "start code from fulcro-spec"?

thheller21:05:20

preloads maybe?

wilkerlucio21:05:44

there is none there

wilkerlucio21:05:06

that's what I'm finding confusing, I have no reference to fulcro-spec on this build

thheller21:05:01

from the clj REPL you can run (shadow.cljs.devtools.api/find-resources-using-ns 'fulcro.spec) or whatever the ns is

thheller21:05:43

no idea why added test code would become part of you build though. maybe a naming conflict?

wilkerlucio21:05:20

other thing, about the nrepl-port, here everytime I run shadow it uses a new port

wilkerlucio21:05:40

I though I read something about it creating a file and sticking to that number, do I have to configure anything for that to happen?

thheller21:05:16

the port is always random and always written to .shadow/nrepl.port by default. you can however configure a fixed port

wilkerlucio21:05:50

do you have a way for cursive to pick the port number from that?

thheller21:05:32

no I use a fixed port due to cursive

wilkerlucio21:05:25

I ran the command you said

wilkerlucio21:05:33

all the references I'm finding are from my test file sources

wilkerlucio21:05:09

is there other way I can try to figure why the spec stuff is leaking into other build?

wilkerlucio21:05:02

I may have found it

thheller21:05:06

there should be ... but currently there is no easy way

wilkerlucio21:05:18

there was a cljs.user in the test directory

wilkerlucio21:05:44

yeah, that was it

wilkerlucio21:05:01

the experience with chrome + shadow is been awesome, even still incomplete, I'm close to have a beta for fulcro-inspect running as a chrome devtool 🙂

parrot 4
thheller21:05:12

nice. I'll probably work on it a bit more tomorrow.