This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-31
Channels
- # announcements (6)
- # babashka (32)
- # beginners (78)
- # biff (11)
- # calva (7)
- # clj-kondo (20)
- # clojure (35)
- # clojure-europe (10)
- # clojure-nl (4)
- # clojure-norway (8)
- # clojure-uk (2)
- # clojurescript (41)
- # conjure (14)
- # core-async (10)
- # cursive (7)
- # datomic (12)
- # deps-new (4)
- # emacs (15)
- # fulcro (48)
- # gratitude (11)
- # hugsql (1)
- # hyperfiddle (3)
- # introduce-yourself (3)
- # jobs (3)
- # klipse (2)
- # off-topic (7)
- # polylith (30)
- # reitit (1)
- # remote-jobs (1)
- # reveal (8)
- # scittle (4)
- # shadow-cljs (40)
- # squint (13)
- # tools-deps (7)
- # xtdb (7)
Is it possible to access the source map during execution? I am trying to build a "better" tap> that automatically includes the source location. A fake js/Error. gives me a js stacktrace from which I can get the js line number of the callsite, but I want to map this back to cljs. I looked at some of the cljs.util functions, but they are java only apparently.
I did this by making it macro and just grabbing the location data from &form
meta https://github.com/thheller/shadow-cljs/blob/43a229c6f797030d2bb39382ab1ead465d36c46c/src/main/shadow/debug.clj#L33
@thheller Ah, that's very cool. I actually wanted to use this with shadow-cljs 🙂 Would it be an idea to include this info for all entries in the Inspect tabs?
already is. well, some of the info got lost I guess. still shows the namespace though 😛
@thheller OK, I think we are running the latest version, and I see :cljs - :app - :browser for all entries.
I usually have a require like this [shadow.debug :refer (?> ?-> ?->>)]
and just use those instead of tap>
@thheller Looks like it will render both line and col if it is there, so it must be missing somehow.
there is also (?> the-val :some-label)
which is useful if you want a quick label for a thing
A very newbie question, but what would be an ClojureScript counterpart of the JavaScript statement const { value } = event.target;
? The record accessing and unpacking is the tricky part for me.
(let [value (.-value (.-target event))])
{ value }
is accessing the value
property off the target
property@U0HJ7CX6H Wow, thanks! I'm also new to JavaScript as well 😅
no problem 🙂
whenever you see const { someName } = someObject;
its destructuring the someObject
, sort of similar to {:keys [someName]} someObject
destructuring in Clojure
Oh yeah, it makes sense because JS objects are like records, which Clojure maps are also like.
yes! that works nicely when you want to access a property deep inside an object
there's also https://github.com/applied-science/js-interop which is incredibly useful when you need to do a lot of accessing of JS objects
but i highly suggest working with .-
, .
, and ..
before using the lib if you're still new to Clojure
Wow, I was writing something like (-> event .-target .-value)
, but ..
seems to be cleaner.
Context: I am translating the following method of a React component:
handleChange(event) {
const { value } = event.target;
this.setState({ value });
}
is it possible with hiccup to escape a /
[
or ]
in a CSS class name while using the .
syntax? e.g. [:div.foo-md[5/7]]
. or should i use :class ["foo-md[5/7]"]
?
Definitely the latter. I would suggest using it even when you don't need to escape anything.
But also, I'd double check that the characters [
, /
, and ]
are valid in CSS class names.
I'm guessing this is tailwind (or similar) usage. To work around /
being a problem, we just changed it to underscore in our app. Haven't needed to deal with [
yet, we just stayed on tailwind 2.
@U2FRKM4TW: is there a reason to use the less concise version other than the syntax difficulties?
Consistent style (class collections with conditional classes are another thing that makes this shortcut useless), ability to search by proper keywords, ability to easily update your own hiccup programmatically.
@U08JKUHA9 correct, tailwind has such classes
but interesting idea to remap to underscore
Yea we prefer that syntax despite those drawbacks. For []
, we'll probably just think of a reasonable replacement, or just always use those specifically via :class
Hi there, I'm looking to monkeypatch js/console.error
so I can observe some errors that are being produced from library code. I'd like to adapt something like this to cljs:
var originalConsoleLog = console.log;
console.log = function(text) {
if (text === "something") { doSomething()}
originalConsoleLog.apply(console, arguments);
}
The portion I'm not so sure about is
originalConsoleLog.apply(console, arguments);
(let [orig js/console.log
side-effect #(when (#{"something"} %1) (do-something))]
(set! js/console.log (juxt orig side-effect)))