(def protocols (atom {}))
(defmacro reify-protocol [p]
`(do
(swap! protocols
(fn [ps] (if-not (contains? ps ~p) (assoc ps p {:satisfies (fn [o] (satisfies? ~p o))}))
(quote ~p)))
something like this
reify protocols as needed
Hi, I'm starting a new project with clojurescript and i got this error: C:\myprojects\cljs λ powershell -command clj -X:new :template figwheel-main :name learn-cljs/weather :args '["+deps" "--reagent"]' Downloading: figwheel-main/lein-template/maven-metadata.xml from clojars Unknown option '+deps' --> Perhaps you intended to use the '+deps' option? C:\myprojects\cljs λ What did I miss?
it's escaping issue. powershell -command clj -X:new clj-new/create :template figwheel-main :name learn-cljs/weather :args '[""""""+deps"""""" """"""--reagent""""""]' now it works. thanks to https://twitter.com/asmeredith
I have written a few inline macros to process some files in cljs on startup, these call out to functions in clj how ever the macros fail because they can not see the clj functions is there a way around this ?
do I have to contain all the code in the macro or are there other options ?
Either you're using self-hosted CLJS and macros in CLJS or those CLJ files are not on your classpath. If it's the former, you will probably need to convert those CLJ files into CLJC. If it's the latter, you just have to fix your classpath. I have no idea how else the behavior that you see could be caused.
so I have the macros in src/clj/macros.clj and src/clj/functions.clj I have "src/clj" and "src/cljc" on the class path, then another project which is cljs I want to inline require the macros to do the processing of some files
https://gitlab.com/olymk2/cl-org/-/blob/master/src/clj/cl_eorg/macros.clj
This is a library I have been writing to learn various things so the macro side is new to me
You're returning quoted forms. Instead of inlining the contents of the files, it just embeds the calls to CLJ functions into the CLJS code.
ah that makes sense, they used to not be quoted but I think it helped solve a problem, obviously the wrong fix I will revert that and see what happens, cheers 🙂
awesome fixed, and i fixed the original issue as well 🙂
How can I bind a cljs function to buttons onclick event? My try results in a init error:
(defn generate []
do-some-stuff)
(defn init []
(-> js/document
(.getElementById "generate-button")
(.onclick generate)))
You need to call set!
for a proper JS interop. Check out this cheatsheet for an example: https://cljs.info/cheatsheet/
You are calling .onclick
. try (.addEventListener "click" generate")
instead of (.onclick ..)
Getting "does not compile" on
(defn init []
(-> js/document
(.getElementById "generate-button")
(.onclick)
(set! generate)))
works ... thanx 🙂
That's because it should've been .-onclick
. And IMO you're overusing the threading macro.
(let [btn (.getElementById js/document "generate-button")]
(set! (.-onclick btn) generate))
But thheller's advice is better anyway.You are still calling element.onclick()
.
(set! -onclick generate)
would be ok too
Where did the button go? :)
in the ->
variant
Oh wow. It's not even documented.
what is the canonical way to parse a string timestamp into an inst?
If you mean parsing a string of the same format that you see when printing an inst, then probably the default inst
reader tag implementation, clojure.instant/read-instant-date
.
or in clojurescript cljs.reader/parse-timestamp
?
Ah, didn't notice we're in #clojurescript
The default implementation uses cljs.tagged-literals/read-inst
. But in the end it uses cljs.reader/parse-timestamp
, yes, after a string?
check.
thanks!