Hi, is it possible to mix ClojureScript and JavaScript in single project and compile them to a single .js file?
on penpot, we have many js files among the cljs files
shadow-cljs is awesome for it
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
I can provide examples if you need 😉
sounds awesome! could you share it to us?
https://github.com/penpot/penpot/blob/develop/frontend/src/app/util/text_editor_impl.js
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]
https://github.com/penpot/penpot/blob/develop/frontend/src/app/util/quadtree.js
is using gclosure module format
and we require it like any other cljs namespace [app.util.quadtree :as qdt]
the second format works in both shadow-cljs and regular cljs compiler, the first one (ES module format) is shadow-cljs only
each one has its own tradeoffs and advantatges
cool!
It helps a lot, thanks for your kind sharing!
feel free to ask if you have more doubts 😉
The customer told us they can't write cljs and we are considering js plugins for them.
#shadow-cljs makes it possible I guess.
cool, found a experimental feature in shadow-cljs https://shadow-cljs.github.io/docs/UsersGuide.html#classpath-js
https://github.com/hashql/hashql I think this is kind of clever, and something we could do in Clojure(Script) too
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
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.
hello, is there any lib that i can read and write excel in cljs in electron
If you don't find anything specifically for CLJS, you can search for a JS library and just use it via interop.
yes, i found this lib, https://github.com/exceljs/exceljs#reading-xlsx, but i don't know how to interop this in cljs
(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)))
)
))
)
i try this for prn each row, but it seems cant
Why did you use Promise.resolve
there?
The original JS examples on that page don't use it.
because it
await workbook.xlsx.readFile(filename);
It's just .then
, without any extra explicit promise creation.
An async JS function already returns a promise - use interop with it, that's it.
So, in your code above, just remove js/Promise.resolve
.
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)))
))))
now i want to prn each row
how can i do this?
Just uncomment the last two commented lines?
Ah, and wrap
Actually, that's not needed. I never use eachRow
in ()
along with the function itself..
so I don't remember its syntax.
(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))))
))))
Does it not work?
nothing is print
No idea, I would try coming up with a JS example first for that particular spreadsheet. Then I'd try debugging.
(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))))
;; )
)))
code like this it doesn't output hello
How do you run the code?
in emacs, connect to shadow-cljs repl
Evaluate this:
(let [p (js/Promise. (fn [resolve _] (js/setTimeout #(resolve "hello") 500)))]
(.then p js/console.log))
Does it output "hello"
?no
(prn "hello")
this can output
Your REPL setup doesn't catch print statement in async functions, that's it. Maybe asking in #shadow-cljs will help.
ok, thank u very much
sorry, it output in the console, not in repl, i didn't see it
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?
I recall something called secretary ..
relevant maybe? https://github.com/clj-commons/secretary