This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-09-19
Channels
- # announcements (1)
- # beginners (115)
- # calva (7)
- # cider (8)
- # clj-kondo (3)
- # cljdoc (12)
- # clojure (50)
- # clojure-europe (4)
- # clojure-italy (5)
- # clojure-nl (6)
- # clojure-spec (70)
- # clojure-uk (88)
- # clojurescript (54)
- # core-async (16)
- # cursive (5)
- # datomic (31)
- # editors (4)
- # emacs (4)
- # fulcro (29)
- # graphql (17)
- # luminus (1)
- # lumo (2)
- # off-topic (37)
- # pathom (16)
- # random (2)
- # re-frame (5)
- # reitit (3)
- # rum (2)
- # shadow-cljs (192)
- # sql (11)
I am trying to debug a rum/citrus app. https://github.com/clj-commons/citrus It queues UI events using a private function
(defn- queue-effects! [queue f]
(vswap! queue conj f))
I would like to instrument this with an extra
(.log js/console "queue-effects! added" f)
so I can see what is going into the queue.
I've tried
(with-redefs [citrus.reconciler/queue-effects! instrumented-queue-effects!]
(citrus/reconciler {:state (atom {})
but my instrumented function doesn't seem to get called
Is there an idiomatic way to do this?
I'm not very familiar with the Clojurescript runtimeI cannot just inclued
(ns citrus.reconciler)
(defn queue-effects! [q f]
(.log js/console "queue-effects! added" f)
(vswap! q conj f))
in my startup namespace; I get the error
base.js:305 Uncaught Error: Namespace "citrus.reconciler" already declared.
at Object.goog.provide (base.js:305)
at main.cljs?rel=1568887947127:50
`I think that the problem is with-redef, it only applies redefinition when you are in scope of with-redef
Perfect!
thankyou
How do I do the following in clojurescript, when it doesn't have var
? (basically stubbing and restoring a variable)
user=> (def x 1)
#'user/x
user=> (def hold [(var x) x])
#'user/hold
user=> (alter-var-root #'x (fn [_] 5))
5
user=> x
5
user=> (let [[variable value] hold] (alter-var-root variable (fn [_] value)))
1
user=> x
1
The var is an ordinary defn in my application, and I want to stub it in my tests (`with-redefs` won't work since it gets called outside its scope)
I've been doing that (hopefully it's okay just for testing) but I'm having problem saving that.ns/foo
to an atom, so I can restore its original value.
It seems to work in Clojure where I can save (var that.ns/foo)
, but I can't figure out how to get the reference to that.ns/foo
in clojurescript so I can set!
it back to its original value in my fixtures.
yeah thats not possible. you can however store a function if you have to? #(set! that.js/foo %)
?
That works great for my use case!
(let [orig-fn fetch/session]
(set! fetch/session (stub-fetch-fn "anon-token"))
(swap! stubbed-variables conj #(set! fetch/session orig-fn)))
Then I just run all those functions in my fixtures. Not too hairy for me. Thanks!@norbertpy no, not really. I think the barrier is that glimmerja requires a whole compilation toolchain itself and only works with TypeScript, so it's not very friendly to langs like CLJS building on top of it
Instead of
(ns app.core
(:require [lib1.namespace1 :as namespace1]
[lib1.namespace2 :as namespace2] ... )
is it possible to require all? something like
(ns app.core
(:require [lib1 :as lib1] ... )
(lib1/namespace1/foo ...)
?you can require them without aliasing with :as
, but you can’t require the top-level ns and get everything underneath it
Hm oki... I use a ui wrapper and each component is in a different namespace, I wanted to reduce the size of the :require, but it's not a big deal 🙂
To give some confidence into the pragmatism of full requires : when your app scales it’s still searchable. I use the requires to work my way through large codebases 🙂 I actually think this is a super power of Clojure. Because the language is consistent and light on syntax it’s very easy to find things.
I've been working forever on a pretty fun frontend. Its been working great with figwheel and the repl. I went to build it for the first time in forever (`uberjar`). I can make it compile and work but with no optimizations or any setting changes really. Even changing :pretty-print
to false
in :cljsbuild
give me invalid hiccup
errors in my console. Anyone got any clues for me?
i'm attempting to use @material-ui/core
^4.0.0 with shadow-cljs
and reagent
, however i get the following exception when attempting to use a Button component:
Uncaught TypeError: _react.default.useContext is not a function
does this indicate a ReactJS / hooks related problem?I'm very confused...
Caused by: clojure.lang.ExceptionInfo: Call to clojure.core/defn- did not conform to spec. {:clojure.spec.alpha/problems [{:path [:fn-name], :pred clojure.core/simple-symbol?, :val clj-tuple/conj-tuple, :via [:clojure.core.specs.alpha/defn-args :clojure.core.specs.alpha/defn-args], :in [0]}], :clojure.spec.alpha/spec #object[clojure.spec.alpha$regex_spec_impl$reify__2509 0x2e090fb7 "clojure.spec.alpha$regex_spec_impl
@sova that error isn’t helpful without the associated code. best guess: you gave it a weird function or arg name
i cloned this project as a starting point which works like a charm, and then stripped out everything in the UI except for the Button in order to start small
https://github.com/maxp/shadow-cljs-mui
then i bumped @material-ui/core
via yarn and that's when the exception started
hmm, it looks like i bumped react
but not react-dom
😇 thanks @U4YGF4NGM
actually it is a result of including [stripe-clojure.core :as s]
someone mentioned it could be pulling in a transitive dependency on an old clojure.async? what to do
it's only using
[[org.clojure/clojure "1.6.0"]
[clj-http "1.0.1"]]
(ns stripe-clojure.core
"Functions for Stripe Customers API"
(:require [clj-http.client :as client])
(:refer-clojure :exclude (list)))
why does it obliterate (defn-) when i include stripe-clojure?
(not actually a clojurescript question i guess?)
whatever i'll try another lib
I don’t know what you mean @sova. the error is saying it’s having trouble parsing a defn-
somewhere, maybe in the stripe-clojure lib?
s'pose so.
@sova for what it's worth, a friend had a lot of trouble using <some-stripe-cljs-library> and eventually went for direct js/cljs interop. i don't know if it was the same library, but it was a few versions behind stripe's current version.
yeah the stripe-clojure lib seems pretty small, probably not worth going into it’s transitive deps to try and tease it out
yeah it looks like the best way to stripe-ify things is to just use their REST api yourself