Fork me on GitHub
#clojurescript
<
2021-11-25
>
Febin John James05:11:27

Is there any material on building a clojure wrapper for js library that's has an Object Oriented Design.

emccue06:11:12

Define object oriented design

emccue06:11:25

and maybe share the library in question

emccue06:11:15

the benefit of doing a wrapper is usually pretty small unless you are using it extensively and its existing api is bad in some noteworthy way

Febin John James07:11:34

Someone has made a wrapper for this few years ago https://github.com/dparis/phzr

Febin John James07:11:39

But it's old now.

Febin John James07:11:03

I am trying to make a wrapper for the latest version.

Febin John James07:11:08

If i use the library directly, i feel my clojure code is turning into something like OOPs instead of functional design.

emccue19:11:01

How old is it now? If it's design is solid you can probably update it easier than writing a new wrapper

emccue19:11:27

It mostly just seems to replace method calls with a protocol so access is uniform

Febin John James23:11:05

6 years. I will reach out to the author and ask him some directions. Thanks

metehan06:11:33

I am trying to achieve register functions with macro apparently I am doing it wrong:

(ns spill.tools.adapters.recharts
  (:require
   [reagent.core :refer [adapt-react-class]]
   ["recharts" :as rc]))

(defmacro adapt-react [name class]
  `(defn ~name
     ([] [~name nil nil])
     ([opts] [~name opts nil])
     ([opts content] [(adapt-react-class ~class) opts content])))

(adapt-react "line-chart" rc/LineChart)
(adapt-react "pie-chart" rc/PieChart)
(adapt-react "label" rc/Label)

emccue06:11:13

(defmacro adapt-react [name class]
  `(defn ~(symbol name)
     ([] [~name nil nil])
     ([opts] [~name opts nil])
     ([opts content] [(adapt-react-class ~class) opts content])))

p-himik06:11:57

Or replace the strings with symbols at the usage sites. An extra benefit - your IDE could pick those up.

p-himik06:11:38

But instead of doing all that, it's much better to just

(def line-chart (adapt-react-class rc/LineChart))

metehan06:11:57

thank you. I didn't notice macro is not necessary at first place 🙂

👍 1
metehan07:11:19

cljs.user=> (defmacro just-test [name x] `(defn ~name [y] (* ~x y)))
true
cljs.user=> (just-test (symbol "xtwo") 2)
Wrong number of args (2) passed to cljs.user/just-test at line 1 

metehan07:11:53

why it says wrong number of arguements

metehan07:11:15

and different error on my console

p-himik07:11:07

Because inside the macro, name is not 'xtwo, the symbol, but rather it's '(symbol "xtwo") - a list of a symbol and a string. Forms are passed as is to macros - they are not evaluated.

metehan08:11:05

thank you again 🙂

👍 1
sarna09:11:57

hey, I'm getting a weird error when trying out this in emacs https://github.com/Gonzih/cljs-electron error in process filter: nrepl-send-sync-request: Sync nREPL request timed out (op eval code (require 'figwheel-sidecar.repl)) error in process filter: Sync nREPL request timed out (op eval code (require 'figwheel-sidecar.repl)) the only hit I got is from archive, with no solution 😞 https://clojurians-log.clojureverse.org/clojurescript/2019-06-26 any ideas? if there's anything more up to date than this setup I could use that instead too

sarna10:11:00

thanks for the link, I haven't found any solutions there though.. all of these link to "hey I have this problem" and no follow up

sarna11:11:54

found kind of a workaround: the command that times out is pasted in the repl window, you can copy it and re-run it in the repl. timeout seems to be set from emacs/cider side so if you run it manually it'll succeed

sarna11:11:40

for some commands I still get "nrepl not connected" but I guess that's another issue and I switched to https://github.com/ahonn/shadow-electron-starter which seems to work better :)

octahedrion15:11:55

why is ns-publics a macro in Clojurescript ?

p-himik15:11:06

Because the required information does not exist at run time.