This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-18
Channels
- # announcements (7)
- # babashka (4)
- # babashka-sci-dev (73)
- # beginners (101)
- # biff (4)
- # calva (33)
- # clerk (36)
- # clj-commons (23)
- # clj-kondo (3)
- # clojure (38)
- # clojure-europe (2)
- # clojurescript (29)
- # datalevin (15)
- # emacs (2)
- # fulcro (8)
- # gratitude (1)
- # hugsql (9)
- # hyperfiddle (43)
- # jobs-discuss (4)
- # lsp (47)
- # malli (7)
- # off-topic (14)
- # pathom (5)
- # practicalli (1)
- # releases (7)
- # shadow-cljs (4)
- # spacemacs (6)
- # sql (7)
- # tools-deps (7)
- # transit (8)
- # xtdb (6)
I need help, I've been stuck on this for a while. I'm trying to call Stripe, using shadow-cljs (so npm), here's how I'm trying to do things
(ns invoice.backend.main
(:require ["stripe" :as stripe]
[cljs.core.async :refer [go]]
[cljs.core.async.interop :refer-macros [<p!]])) (def stripeKey "key")
(def stripeAccount "account-num")
(def stripe-authed (stripe/Stripe stripeKey)) (def charge (stripe-authed/charges.retrieve ({stripeKey {:stripeAccount stripeAccount}})))
return error
Use of undeclared Var stripe-authed/charges
symbols with a slash are either namespaces or namespace aliases. but striped-auth
is a local var, it cannot be used as an alias. use (-> stripe-auth (.-charges) (.-retrieve #js {stripeKey #js {:stripeAccount stripAccount}}))
Can you tell me where in the documentation this syntax is covered? I'm having a hard time finding it
I found an entry for the threading macro under https://clojure.org/guides/threading_macros and https://clojure.org/guides/weird_characters , but am having trouble finding the entry for the - symbol (under reader?) https://clojure.org/reference/reader https://www.clojurescript.org/guides/reader (to be honest I'm having a difficult time navigating clojurescript's documentation. I don't think I could find the reader guide from the main index)
The .-
is interop with the host - both in CLJ and in CLJS.
Regarding /
- it's here: https://clojurescript.org/about/differences#_host_interop
The interop syntax is not really documented on the
website. Like many other things - because it's not that different from Clojure and it would be mostly repeating the stuff from
(at least, such an explanation seems reasonable to me).
I receive error that javascript literal keys must be strings or unqualified keywords. I think the datastructure
(.retrieve #js {stripeTrans #js {:stripeAccount stripeAccount}})
may not be correct, it is supposed to be formatted as
stripe.charges.retrieve('charge-id', { stripeAccount: 'account number' });
I would think the solution would be
(-> stripe-auth (.-charges) (.-retrieve stripeTrans #js {:stripeAccount stripeAccount})))
However, this returns the error:
dot process access with args
which i don't understandThe next to last code block is correct, apart from the small mistake - there should be no -
.
The .-
is for accessing properties and just .
without -
(thheller made a mistake above) is for calling member functions.
The error is opaque but it basically means that you are trying to pass arguments to a form that accesses a property.
I definitely suggest reading CLJ docs on interop and CLJS cheatsheet on it as well.
I'll read them, and the other docs too, as I'm still pretty green. I think that what thheller meant was that (.-charges) is necessary (rather than (.charges)). I think this is because charges isn't a member function but a property(?). The following did what I wanted:
(-> stripe-authed (.-charges) (.retrieve stripeTrans #js {:stripeAccount stripeAccount})))
I have just discovered by chance pyscript, it would be cool to be able to do the same with clojure https://www.youtube.com/watch?v=vxqBm6_0vyk
Assuming I understood what you mean by "the same", we can already do that with https://github.com/babashka/scittle.
@U04T3JCE9GX Would scittle come close? https://babashka.org/scittle/
Had no idea, I’ll check it out, thanksss !!!
May I ask, what are people most using it for ?
To create a pinball game, among other things :) https://thegeez.net/static/pinball/pinball.html
You can also create a guestbook and use babashka as the server: https://github.com/kloimhardt/babashka-scittle-guestbook The benefit is not having to "build" anything, you can quickly prototype stuff
scittle also works in sites like codepen https://codepen.io/ordnungswidrig/pen/xxpPYNO
Here is an issue tracking what people are doing with it: https://github.com/babashka/scittle/issues/40
wowwwww, you are chatGPT version 1 million, thanksss !!!
Is it just happenstance that :rename works without :refer’ing the var? e.g., the following works (:require [re-frame.core :as rf :rename {reg-event-db edb}])
The https://clojurescript.org/about/differences#_namespaces seem to imply that it should only work from the set of symbols referred.
What do you mean by "works"? Doesn't result in an exception, makes edb
available, makes rf/edb
available, something else?
FWIW, (require '[clojure.string :as str :rename {trim x}])
in CLJ doesn't throw and only makes str
be available as an alias to clojure.string
. The :rename
part has no effect.
In a CLJS Node-based REPL, that expression throws.
Where were you able to find :rename
in the docs? I only know about it from StackOverflow.
:rename
is documented for refer
(https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/refer) and use
, but I don't see it documented for require
. Anyway, on that web page it seems that :rename
is a "filter" applied to "all public vars" in the source namespace.
If it's not already on http://ask.clojure.org for abatement, you should put it there or we should draw lots