This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-02-07
Channels
- # announcements (6)
- # babashka (17)
- # beginners (72)
- # calva (27)
- # cider (26)
- # circleci (6)
- # clj-kondo (35)
- # cljdoc (3)
- # clojure (22)
- # clojure-australia (2)
- # clojure-dev (45)
- # clojure-france (2)
- # clojure-italy (2)
- # clojurescript (60)
- # conjure (16)
- # cursive (8)
- # datahike (10)
- # datascript (1)
- # datomic (3)
- # emacs (5)
- # fulcro (16)
- # graalvm (4)
- # honeysql (1)
- # joker (10)
- # luminus (3)
- # malli (7)
- # off-topic (28)
- # pathom (4)
- # pedestal (2)
- # polylith (1)
- # re-frame (6)
- # reagent (9)
- # reveal (4)
- # shadow-cljs (48)
- # slack-help (1)
- # tools-deps (30)
- # vim (24)
hi. i'm currently working on Bazel integration for clojurescript and have been looking at the compiler options. would it be possible to expose several of the --compile-opts as regular command line options as well?
I'm looking for a memoize last function
I use this one: https://github.com/ptaoussanis/encore/blob/master/src/taoensso/encore.cljc#L1878
I’m trying to use hooks in a react app like so:
(let [elements (useElements)] (if @s/user
[:> div
(e/load-stripe elements)
[:> div (tw [:flex-row])
[:> CardElement {:options (clj->js {:style {:base
{:fontSize "16px"
:color "#424770"
;;:width "30em"
}
:invalid {:color "#9e2146"}}})}]
[:button (tw style/button [:bg-green-700
:text-white
:text-sm]
{:on-click #(dispatch [:purchase-plan])}) "Purchase Plan"]
]
]
[:button (tw style/button [:text-base :bg-green-700
:text-white :m-0
:px-6
:py-5
]
{:on-click #(dispatch [:login])})
"Subscribe to Exclusive Content"
]))
It uses the useElements function.
But I get the error:
react-dom.development.js:14747 Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
How to call the hook correctly?
This section and below: https://github.com/reagent-project/reagent/blob/master/doc/ReactFeatures.md#function-components
thanks
I’m converting the following code to cljs:
const {error, paymentMethod} = await stripe.createPaymentMethod({
type: 'card',
card: cardElement,
});
Here’s the cljs:
(go
(prn "stripe is " stripe)
(let [[error payment-method]
(<! (.createPaymentMethod stripe {:type "card" :card card-element}))]
(prn "error is " error)
(js/console.log "payment method is " payment-method)))
But am getting the error:
IntegrationError: Invalid value for createPaymentMethod: type should be string. You specified: undefined.
How to fix this?createPaymentMethod
expects a JS object but you're giving it a CLJS map.
If card-element
is some JS value, then it can be fixed by just adding #js
in front of the map literal.
There are many ways to work with async JS functions in CLJS, one of them would be to just use the promise API via interop.
Finally, you're trying to destructure a JS object as if it were an array. It won't work - you will have to use JS interop for that.
after adding the #js in front of the map, I’m getting the following error:
IntegrationError: Please use the same instance of `Stripe` you used to create this Element to create your Source or Token.
even though I have a single stripe object that I’m using
I have the following code for Stripe integration:
(if card-element
(go
(prn "stripe is " stripe)
(let [error-payment-method
(<! (.createPaymentMethod stripe #js {:type "card" :card card-element}))]
(prn "error is " error-payment-method)
))
(prn "card element is nil")
)
But this gives me the error
IntegrationError: Please use the same instance of `Stripe` you used to create this Element to create your Source or Token.
How to fix this error?Realized my question in #beginners might not be very beginner-y, and it's been a day, so:
I'm trying to use clojure.spec.test.alpha/check
in a cljs repl, but I constantly get an error about needing to require clojure.test.check
and clojure.test.check.properties
before calling it, even though I did that. Is there a way to make sure the namespaces are properly imported?
/tmp ❯❯❯ clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "RELEASE"} org.clojure/test.check {:mvn/version "RELEASE"}}}' -M -m cljs.main -re node -r
ClojureScript 1.10.773
cljs.user=> (require '[clojure.spec.test.alpha :as spec.test])
nil
cljs.user=> (spec.test/check)
Execution error (Error) at (<cljs repl>:1).
Require clojure.test.check and clojure.test.check.properties before calling check.
cljs.user=> (require 'clojure.test.check 'clojure.test.check.properties)
nil
cljs.user=> (spec.test/check)
[]
cljs.user=>
Using shadow-cljs, have [org.clojure/test.check "1.1.0"]
in my :dependencies
. Using spacemacs a-la http://Practical.li
Could it be a version problem with test.check?
Running your code as above in the repl for my project fails, though it complies if I call clojure
at the command line directly. Weirdly, it fails at the initial (spec.test/check)
, saying no such namespace could be located, even though I did that the line above.
i tried to recreate with just shadow-cljs on the command line and it actually succeeded
shadow-cljs - server version: 2.9.10 running at
shadow-cljs - nREPL server started on port 62853
cljs.user=> (require '[clojure.spec.test.alpha :as spec.test])
nil
cljs.user=> (spec.test/check)
Error: Require clojure.test.check and clojure.test.check.properties before calling check.
at <eval>:3:25
at cljsEval (<eval>:3:137)
at global.SHADOW_NODE_EVAL ([stdin]:105:10)
at Object.shadow$cljs$devtools$client$node$node_eval [as node_eval] (/private/tmp/shadow/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/node.cljs:24:1)
at /private/tmp/shadow/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/node.cljs:49:13
at Object.shadow$cljs$devtools$client$env$repl_call [as repl_call] (/private/tmp/shadow/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/env.cljs:122:11)
at Object.shadow$cljs$devtools$client$node$repl_invoke [as repl_invoke] (/private/tmp/shadow/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/node.cljs:47:1)
at shadow$cljs$devtools$client$node$process_message (/private/tmp/shadow/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/node.cljs:106:5)
at /private/tmp/shadow/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/env.cljs:244:9
at Object.shadow$cljs$devtools$client$env$process_next_BANG_ [as process_next_BANG_] (/private/tmp/shadow/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/env.cljs:196:7)
cljs.user=> (require 'clojure.test.check 'clojure.test.check.properties)
nil
cljs.user=> (spec.test/check)
[]
cljs.user=>
I am using CIDER.
yeah its not working for me in CIDER. can you file an issue on github? a minimal repo is just {:dependencies [[org.clojure/test.check "1.1.0"]]}
as the shadow-cljs.edn file. npm i shadow-cljs. and then jack in clojurescript and choose the node-repl
Will do. Glad to know I wasn't going crazy. 😛
To be clear, I should make an issue on the CIDER repo?
I ask mostly because I'm getting the same issue when running things in shadow-cljs cljs-repl
on the command line
I'll see if I can get a minimal example for that.
/t/shadow ❯❯❯ cat shadow-cljs.edn
{:dependencies [[org.clojure/test.check "1.1.0"]]}
/t/shadow ❯❯❯ shadow-cljs node-repl
shadow-cljs - config: /private/tmp/shadow/shadow-cljs.edn
shadow-cljs - socket connect failed, server process dead?
shadow-cljs - updating dependencies
shadow-cljs - dependencies updated
[2021-02-07 13:54:32.385 - WARNING] TCP Port 9630 in use.
[2021-02-07 13:54:37.557 - WARNING] :shadow.cljs.devtools.server.fs-watch-hawk/hawk-start-ex
ArityException Wrong number of args (0) passed to: clojure.core/juxt
clojure.core/apply (core.clj:665)
clojure.core/apply (core.clj:660)
hawk.core/watch! (core.clj:79)
hawk.core/watch! (core.clj:59)
shadow.cljs.devtools.server.fs-watch-hawk/start* (fs_watch_hawk.clj:42)
shadow.cljs.devtools.server.fs-watch-hawk/start* (fs_watch_hawk.clj:30)
shadow.cljs.devtools.server.fs-watch-hawk/start (fs_watch_hawk.clj:103)
shadow.cljs.devtools.server.fs-watch-hawk/start (fs_watch_hawk.clj:101)
clojure.lang.Var.invoke (Var.java:399)
shadow.cljs.devtools.server.fs-watch/start (fs_watch.clj:26)
shadow.cljs.devtools.server.fs-watch/start (fs_watch.clj:11)
shadow.cljs.devtools.server/start!/fn--17712 (server.clj:407)
shadow-cljs - server version: 2.9.10 running at
shadow-cljs - nREPL server started on port 62853
cljs.user=> (require '[clojure.spec.test.alpha :as spec.test])
nil
cljs.user=> (spec.test/check)
Error: Require clojure.test.check and clojure.test.check.properties before calling check.
at <eval>:3:25
at cljsEval (<eval>:3:137)
at global.SHADOW_NODE_EVAL ([stdin]:105:10)
at Object.shadow$cljs$devtools$client$node$node_eval [as node_eval] (/private/tmp/shadow/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/node.cljs:24:1)
at /private/tmp/shadow/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/node.cljs:49:13
at Object.shadow$cljs$devtools$client$env$repl_call [as repl_call] (/private/tmp/shadow/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/env.cljs:122:11)
at Object.shadow$cljs$devtools$client$node$repl_invoke [as repl_invoke] (/private/tmp/shadow/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/node.cljs:47:1)
at shadow$cljs$devtools$client$node$process_message (/private/tmp/shadow/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/node.cljs:106:5)
at /private/tmp/shadow/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/env.cljs:244:9
at Object.shadow$cljs$devtools$client$env$process_next_BANG_ [as process_next_BANG_] (/private/tmp/shadow/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/env.cljs:196:7)
cljs.user=> (require 'clojure.test.check 'clojure.test.check.properties)
nil
cljs.user=> (spec.test/check)
[]
I was running it for a particular build, so that could be the difference.
How appropriate that I'm trying to shrink a breaking case for something that does generative testing. 😛
Think I got it. Making a repo.
I meant a minimal to break it at the command line, not just in CIDER.
Could be breaking something else, could demonstrate my incorrect dependencies. Either way, useful to know.
My example showed it not working in cider yet working on the command line. A perfect small example
Well, that comes back to where I report the problem. I thought we thought it was just a CIDER thing, but apparently, it's not. Or I've missed something obvious.
https://github.com/cwstra/shadow-test-check a small shadow-cljs project. Installing the deps with
npm install
, then running
npx shadow-cljs watch example
and
node output/example.js
in the project root, before starting the repl with
npx shadow-cljs cljs-repl example
seems to replicate the behavior you found in the CIDER example.
Accidentally had an extra edn file in there. Now it should be fairly minimal, as far as I can tell.
Alrighty.
Issue made. Thanks for the help; I was concerned I had missed something obvious.
Hey, 🙂 I am trying to define a test support macro for a common pattern when testing with go blocks. Could somebody point me in the right direction? This is the pseudocode:
(defmacro deftest-go
[name & body]
`(cljs.test.deftest ~name
(cljs.test.async done#
(cljs.core.async/go
~@body
(done#)))))
This fails due to not being able to resolve deftest macro. I have seen http://blog.fogus.me/2010/09/03/monkeying-with-clojures-deftest/) a different approach, which uses deftest implementation. Thank you!I think I have done it. The first implementation of macro file is:
(ns commons.utils.test-support
(:require
[clojure.test]))
(defonce ^:dynamic
*load-tests* true)
(defmacro deftest-go
[name & body]
(when *load-tests*
`(def ~(vary-meta name assoc :test `(fn []
(cljs.test/async done#
(cljs.core.async/go
~@body
(done#)))))
(fn [] (clojure.test.test-var (var ~name))))))