Fork me on GitHub
#clojurescript
<
2020-03-05
>
myguidingstar02:03:46

@alex.sheluchin walkable is an modern alternative to toucan and does support clojurescript https://walkable.gitlab.io/

sheluchin11:03:27

Thanks, checking it out now. Is Toucan no longer considered "modern"? Just curious.

myguidingstar12:03:59

Frankly Toucan is an Orm, with N+1 problem and inflexibility. It hides database in a global state, so you cant use more than one db throughout your codebase

pre04:03:02

Js interop question: Assuming you're using shadow-cljs, how do you write an equivalent cljs code?

const db = require('db')

const client = new db.Client({
    secret: process.env.DB_SERVER_SECRET
})

fricze09:03:34

probably something like

(ns core.example
 (:require [db :refer [Client]]))

(def client (Client. #js {:secret (aget process "env" "DB_SERVER_SECRET")}))

Michaël Salihi10:03:16

(ns mynamespace
  (:require ["db" :refer [Client]]))

(def client (Client. #js {:secret (.. js/process -env -DB_SERVER_SECRET)}))

👍 8
Michaël Salihi10:03:51

Arf you were faster @UFJD2TV46 🙂

parrot 4
fricze10:03:43

I think that you can now require npm libraries without quotation marks. Ain’t that right? (:require ["db" :refer [Client]]) vs (:require [db :refer [Client]])

Michaël Salihi10:03:23

Yes I think you are right, Clojurescript manages this for several versions however the developer of Shadow-CLJS indicates that the quotes are preferable in order to differentiate the CLJS vs NPM JS libraries. And I'm agree. You confirm @thheller?

thheller10:03:47

yes, absolutely ALWAYS use strings for npm requires

👍 4
👌 4
Michaël Salihi10:03:48

Thx for the confirmation.

thheller11:03:21

FWIW I think strings should be used since it makes it clear for the user that this is JS code and not CLJS. it also helps the compiler since it doesn't have to treat every folder in node_modules as a potential namespace. also no ambiguity when using package names that CLJS would encode like some-dash or @material-ui/foo etc

👍 8
Michaël Salihi10:03:23

Yes I think you are right, Clojurescript manages this for several versions however the developer of Shadow-CLJS indicates that the quotes are preferable in order to differentiate the CLJS vs NPM JS libraries. And I'm agree. You confirm @thheller?

jeroenvandijk10:03:34

Any clojurescript expert interested in helping out with js interop in borkdude/sci? https://github.com/borkdude/sci/pull/282

Mark Bailey15:03:05

Very small CLJS question for y'all

Mark Bailey15:03:19

I have

(defonce booking (atom {:text "Hello!"
                        :status false}))

(defn booking-swap
  []
  (println "updating status")
  (println (swap! booking update-in [:status] #(not %)))
  (println (get-in booking [:status])))

orestis19:03:26

You can also pass “not” just by itself, no need to wrap it in a function

Mark Bailey15:03:19

this is run when I click the booking button. Only problems is (println) on the swap! call returns the correct value. Next (println) for the get-in returns nil

aisamu15:03:37

Missing a deref? (i.e. (println (get-in @booking [:status])))

thegeez15:03:36

@mbbailey96 booking is an atom, so the last println should be

(println (get-in @booking [:status]))

Mark Bailey15:03:06

Thank you! Atom syntax has been unclear to me so far. I was wondering if i needed to deref.

deep-symmetry15:03:08

Say @borkdude, I am getting a warning compiling my sci using project under shadow-cljs and I am wondering if it is something I am doing wrong, something I should open an issue about, or something I should just ignore because everything seems to actually work. Here is the output, in case you can help me choose a direction:

shadow-cljs - config: /Users/james.elliott/git/bytefield-svg/shadow-cljs.edn  cli version: 2.8.90  node: v12.14.1
shadow-cljs - socket connect failed, server process dead?
shadow-cljs - starting via "clojure"
[:lib] Compiling ...
[:lib] Build completed. (80 files, 3 compiled, 1 warnings, 2.43s)

------ WARNING #1 - :undeclared-var --------------------------------------------
 Resource: sci/impl/multimethods.cljc:96:3
--------------------------------------------------------------------------------
  93 | 
  94 | (defn multi-fn-add-method-impl
  95 |   [multifn dispatch-val f]
  96 |   (#?(:clj .addMethod
---------^----------------------------------------------------------------------
 Use of undeclared Var sci.impl.multimethods/clojure
--------------------------------------------------------------------------------
  97 |       :cljs -add-method) ^clojure.lang.MultiFn multifn dispatch-val f))
  98 | 
  99 | (defn defmethod
 100 |   "Creates and installs a new method of multimethod associated with dispatch-value. "
--------------------------------------------------------------------------------

borkdude15:03:59

I might have already fixed that on master. Could you check?

borkdude15:03:23

I guess you can try building with shadow-cljs + sci as a git dep.

deep-symmetry15:03:47

Ah, interesting, this is my first deps.edn project, which should make that much easier to try! I will do a little research and report back. Thanks!

borkdude15:03:39

you can also join #babashka for sci questions

borkdude15:03:17

maybe shadow-cljs has difficulty processing the type hint ^clojure.lang.MultiFn?

borkdude15:03:30

I don't know if shadow-cljs uses the normal CLJS compiler, that has no problem with it

thheller16:03:34

it does use the normal CLJS compiler but has a bit stricter validation on some things ...

deep-symmetry15:03:44

Ok, I will move future questions over there. I can report that I see the exact same error using master with git SHA f2424029275dac218396d9d532a8bb757aaac1db though.

borkdude15:03:53

but we can re-org the reader conditionals a bit if it's a problem

borkdude15:03:14

I think the type hint should be moved inside the :clj branch maybe

deep-symmetry15:03:28

I am unfortunately a complete ClojureScript newbie, so an issue is all I can offer.

borkdude15:03:33

so just make two more elaborate branches for both :clj and :cljs

borkdude15:03:08

that's fine too. can you make a repro?

deep-symmetry15:03:23

I’ll give it a shot. Thanks again!

deep-symmetry15:03:49

Well, if checking out my project counts as a repro, we have one today.

deep-symmetry15:03:19

(with a walk-through of the build)

lilactown15:03:48

this proposal seems pretty amazing: https://github.com/tc39/proposal-record-tuple

✔️ 4
isak15:03:55

If this happens, they should allow them to be sent to web workers without serializing

borkdude15:03:39

@deep-symmetry Can you just try again with f3f3619ec8d217b08a299604adee21c57dc50181?

deep-symmetry15:03:33

Just in time before my meeting! It compiles cleanly. 🎉

borkdude15:03:57

ok, no need to make an issue then. 🙂

👍 4