clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
weiqiu 2021-05-08T02:41:22.190300Z

Hi, is it possible to mix ClojureScript and JavaScript in single project and compile them to a single .js file?

niwinz 2021-05-08T08:44:56.194800Z

on penpot, we have many js files among the cljs files

niwinz 2021-05-08T08:45:02.195Z

shadow-cljs is awesome for it

niwinz 2021-05-08T08:46:20.195200Z

you have two options: use the ES Modules format or google closure module format, the advantage of using gclosure module format, is that is 100% transparent to cljs and you can (:require it like any other cljs namespace

niwinz 2021-05-08T08:49:16.195400Z

I can provide examples if you need 😉

weiqiu 2021-05-08T08:52:55.195600Z

sounds awesome! could you share it to us?

niwinz 2021-05-08T08:55:42.196100Z

this is an example usin ES module, we integrate with draft editor here and prefer doing it on JS, we just import it using the ["./text_editor_impl.js" :as impl]

niwinz 2021-05-08T08:56:05.196600Z

is using gclosure module format

niwinz 2021-05-08T08:56:51.196800Z

and we require it like any other cljs namespace [app.util.quadtree :as qdt]

niwinz 2021-05-08T08:57:48.197Z

the second format works in both shadow-cljs and regular cljs compiler, the first one (ES module format) is shadow-cljs only

niwinz 2021-05-08T08:59:05.197200Z

each one has its own tradeoffs and advantatges

weiqiu 2021-05-08T09:02:02.197400Z

cool!

weiqiu 2021-05-08T09:02:40.197600Z

It helps a lot, thanks for your kind sharing!

niwinz 2021-05-08T09:13:28.197900Z

feel free to ask if you have more doubts 😉

weiqiu 2021-05-08T02:44:23.190400Z

The customer told us they can't write cljs and we are considering js plugins for them.

t-cool 2021-05-08T06:21:59.190800Z

#shadow-cljs makes it possible I guess.

❤️ 1
weiqiu 2021-05-08T06:32:25.191Z

cool, found a experimental feature in shadow-cljs https://shadow-cljs.github.io/docs/UsersGuide.html#classpath-js

🎉 1
lilactown 2021-05-08T14:29:33.199400Z

https://github.com/hashql/hashql I think this is kind of clever, and something we could do in Clojure(Script) too

lilactown 2021-05-08T14:30:47.200500Z

reading the source, it's a library that allows you to write a SQL query in your source, and at compile time will generate a hash for the client and a lookup on the server side for that hash

p-himik 2021-05-08T15:28:05.201800Z

With macros, it should be possible to do that with anything, not just SQL queries. But I'm not sure if it's a good thing to do - both for SQL and for any other things.

vinurs 2021-05-08T15:30:14.202400Z

hello, is there any lib that i can read and write excel in cljs in electron

p-himik 2021-05-08T16:04:53.202600Z

If you don't find anything specifically for CLJS, you can search for a JS library and just use it via interop.

vinurs 2021-05-08T16:07:24.202800Z

yes, i found this lib, https://github.com/exceljs/exceljs#reading-xlsx, but i don't know how to interop this in cljs

vinurs 2021-05-08T16:10:03.203500Z

(let [workbook (Excel/Workbook.)
      file (.-xlsx workbook)]
  (.then (js/Promise.resolve (.readFile file "/Users/vinurs/Downloads/test.xlsx"))
         #(do
            (let [worksheet (. % getWorksheet 1)]
              (prn worksheet)
              (.  worksheet eachRow (fn [row rownumber]
                                      (prn row)))
              )
            ))
  )

vinurs 2021-05-08T16:10:17.203700Z

i try this for prn each row, but it seems cant

p-himik 2021-05-08T16:14:38.203900Z

Why did you use Promise.resolve there?

p-himik 2021-05-08T16:15:05.204100Z

The original JS examples on that page don't use it.

vinurs 2021-05-08T16:15:36.204300Z

because it

await workbook.xlsx.readFile(filename);

p-himik 2021-05-08T16:16:28.204500Z

It's just .then, without any extra explicit promise creation.

p-himik 2021-05-08T16:16:41.204700Z

An async JS function already returns a promise - use interop with it, that's it.

p-himik 2021-05-08T16:16:55.204900Z

So, in your code above, just remove js/Promise.resolve.

vinurs 2021-05-08T16:19:00.205100Z

like this ?

(let [workbook (Excel/Workbook.)
      file (.-xlsx workbook)]
  (.then (.readFile file "/Users/vinurs/Downloads/test.xlsx")
         #(do
            (let [worksheet (. % getWorksheet 1)]
              (prn worksheet)
              (prn (. worksheet getRow 1))
              ;; const row = worksheet.getRow(5);
              ;; (.  worksheet eachRow (fn [row rownumber]
              ;;                         (prn row)))
              ))))

vinurs 2021-05-08T16:20:02.205300Z

now i want to prn each row

vinurs 2021-05-08T16:20:33.205500Z

how can i do this?

p-himik 2021-05-08T16:20:41.205700Z

Just uncomment the last two commented lines?

p-himik 2021-05-08T16:21:08.205900Z

Ah, and wrap eachRow in () along with the function itself. Actually, that's not needed. I never use . so I don't remember its syntax.

vinurs 2021-05-08T16:23:23.206300Z

(let [workbook (Excel/Workbook.)
      file (.-xlsx workbook)]
  (.then (.readFile file "/Users/vinurs/Downloads/test.xlsx")
         #(do
            (let [worksheet (. % getWorksheet 1)]
              (prn worksheet)
              (prn (. worksheet getRow 1))
              (.  worksheet (eachRow (fn [row rownumber]
                                      (prn row))))
              ))))

p-himik 2021-05-08T16:23:47.206500Z

Does it not work?

vinurs 2021-05-08T16:23:56.206700Z

nothing is print

p-himik 2021-05-08T16:24:42.206900Z

No idea, I would try coming up with a JS example first for that particular spreadsheet. Then I'd try debugging.

vinurs 2021-05-08T16:29:33.207100Z

(let [workbook (Excel/Workbook.)
      file (.-xlsx workbook)]
  (.then (.readFile file "/Users/vinurs/Downloads/test.xlsx")
         #(do
            (prn "hello ")

            ;; (let [worksheet (. % getWorksheet 1)]
            ;;   ;; (prn worksheet)
            ;;   ;; (prn (. worksheet getRow 1))
            ;;   ;; (.  worksheet (eachRow (fn [row rownumber]
            ;;   ;;                         (prn row))))
            ;;   )
            )))

vinurs 2021-05-08T16:29:43.207300Z

code like this it doesn't output hello

p-himik 2021-05-08T16:31:23.207500Z

How do you run the code?

vinurs 2021-05-08T16:31:51.207700Z

in emacs, connect to shadow-cljs repl

p-himik 2021-05-08T16:35:41.207900Z

Evaluate this:

(let [p (js/Promise. (fn [resolve _] (js/setTimeout #(resolve "hello") 500)))]
  (.then p js/console.log))
Does it output "hello"?

vinurs 2021-05-08T16:36:30.208100Z

no

vinurs 2021-05-08T16:37:15.208300Z

(prn "hello")

vinurs 2021-05-08T16:37:18.208500Z

this can output

p-himik 2021-05-08T16:41:39.208700Z

Your REPL setup doesn't catch print statement in async functions, that's it. Maybe asking in #shadow-cljs will help.

vinurs 2021-05-08T16:43:32.208900Z

ok, thank u very much

👍 1
vinurs 2021-05-08T17:09:01.209200Z

sorry, it output in the console, not in repl, i didn't see it

👍 1
2021-05-08T21:10:45.212Z

I'm building a react native app using shadow-cljs, expo, re-frame, reagent. Struggling a little bit to make react-navigation work properly, and I was wondering if anyone can point me to best practices on how to implement it in the most idiomatic clojure way?

sova-soars-the-sora 2021-05-08T23:22:50.214300Z

I recall something called secretary ..

sova-soars-the-sora 2021-05-08T23:23:03.214500Z

relevant maybe? https://github.com/clj-commons/secretary