clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
emccue 2021-02-26T01:54:46.094500Z

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

emccue 2021-02-26T01:57:33.094800Z

something like this

emccue 2021-02-26T01:57:41.095100Z

reify protocols as needed

Cj Pangilinan 2021-02-26T06:55:31.096Z

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 Pangilinan 2021-02-26T07:30:25.096100Z

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

😱 2
oly 2021-02-26T11:43:49.098100Z

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 ?

oly 2021-02-26T11:44:05.098500Z

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

p-himik 2021-02-26T11:47:57.098600Z

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.

oly 2021-02-26T11:51:52.098800Z

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

oly 2021-02-26T11:52:56.099300Z

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

p-himik 2021-02-26T11:55:00.099500Z

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.

oly 2021-02-26T11:56:14.099700Z

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 🙂

👍 1
oly 2021-02-26T12:20:12.100100Z

awesome fixed, and i fixed the original issue as well 🙂

jerger_at_dda 2021-02-26T16:31:59.102100Z

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-himik 2021-02-26T16:34:07.102200Z

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

thheller 2021-02-26T16:35:52.103Z

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

jerger_at_dda 2021-02-26T16:38:31.103100Z

Getting "does not compile" on

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

jerger_at_dda 2021-02-26T16:40:04.103300Z

works ... thanx 🙂

p-himik 2021-02-26T16:44:40.103500Z

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.

thheller 2021-02-26T16:44:41.103700Z

You are still calling element.onclick().

thheller 2021-02-26T16:44:55.103900Z

(set! -onclick generate) would be ok too

p-himik 2021-02-26T16:48:03.104100Z

Where did the button go? :)

thheller 2021-02-26T16:49:00.104300Z

in the -> variant

p-himik 2021-02-26T16:51:52.104500Z

Oh wow. It's not even documented.

2021-02-26T20:18:27.105300Z

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

p-himik 2021-02-26T20:23:25.105400Z

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.

2021-02-26T20:55:54.105600Z

or in clojurescript cljs.reader/parse-timestamp?

p-himik 2021-02-26T21:18:39.105800Z

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.

2021-02-26T22:03:10.106Z

thanks!