Fork me on GitHub
#clojurescript
<
2021-02-26
>
emccue01:02:46

(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)))

emccue01:02:33

something like this

emccue01:02:41

reify protocols as needed

Cj Pangilinan06:02:31

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?

Cj Pangilinan07:02:25

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

šŸ˜± 6
oly11:02:49

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 ?

oly11:02:05

do I have to contain all the code in the macro or are there other options ?

p-himik11:02:57

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.

oly11:02:52

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

oly11:02:56

This is a library I have been writing to learn various things so the macro side is new to me

p-himik11:02:00

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.

oly11:02:14

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 šŸ™‚

šŸ‘ 3
oly12:02:12

awesome fixed, and i fixed the original issue as well šŸ™‚

jerger_at_dda16:02:59

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)))

p-himik16:02:07

You need to call set! for a proper JS interop. Check out this cheatsheet for an example: https://cljs.info/cheatsheet/

jerger_at_dda16:02:31

Getting "does not compile" on

(defn init []
  (-> js/document
      (.getElementById "generate-button")
      (.onclick)
      (set! generate)))

p-himik16:02:40

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.

thheller16:02:41

You are still calling element.onclick().

thheller16:02:55

(set! -onclick generate) would be ok too

p-himik16:02:03

Where did the button go? :)

thheller16:02:00

in the -> variant

p-himik16:02:52

Oh wow. It's not even documented.

thheller16:02:52

You are calling .onclick. try (.addEventListener "click" generate") instead of (.onclick ..)

jerger_at_dda16:02:04

works ... thanx šŸ™‚

Michael Stokley20:02:27

what is the canonical way to parse a string timestamp into an inst?

p-himik20:02:25

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.

Michael Stokley20:02:54

or in clojurescript cljs.reader/parse-timestamp?

p-himik21:02:39

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.