This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-04
Channels
- # announcements (7)
- # babashka (26)
- # babashka-sci-dev (19)
- # beginners (66)
- # calva (4)
- # clj-kondo (55)
- # cljs-dev (173)
- # cljsrn (17)
- # clojure (86)
- # clojure-art (3)
- # clojure-australia (1)
- # clojure-europe (24)
- # clojure-india (1)
- # clojure-nl (3)
- # clojure-uk (6)
- # clojured (5)
- # clojurescript (39)
- # cursive (8)
- # data-oriented-programming (20)
- # datomic (9)
- # emacs (10)
- # events (1)
- # figwheel-main (16)
- # fulcro (33)
- # gratitude (1)
- # helix (2)
- # hugsql (2)
- # jobs (2)
- # kaocha (4)
- # leiningen (5)
- # lsp (110)
- # malli (1)
- # missionary (17)
- # observability (3)
- # re-frame (10)
- # reagent (1)
- # reitit (7)
- # rewrite-clj (3)
- # shadow-cljs (63)
- # sql (19)
- # tools-build (74)
- # tools-deps (32)
- # transit (1)
- # xtdb (5)
Hey. I want to save a https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview before and after every function in my app. Cljs doesn't have alter-var-root and I haven't figured out how to refer to the original function after I set! it to a new function. e.g.
(defn hello [] (println "hello world"))
(set! hello (fn [] (println "before") (hello)))
(hello)
recurses infinitely.
If I had alter-var-root or something like it then I'd try to iterate through (ns-interns ')
and modify each function.
I also looked through the :compile-prepare
shadow build context but I didn't find anything that I could use.
Thanks!not sure exactly what you're trying to do, but Chrome let's you profile your app and save it to a json file. You could then post process it that with a sourcemap.
there are a few other options, but it's not clear what your end goal is.
(map #(alter-var-root %
(fn [f]
(fn [& args]
(println "before")
(apply f args)
(println "after"))))
(vals (ns-interns ')))
I want to instrument every function in my namespace.I'm actually interested in generate a trace and then importing it into chrome to browse it.
right, but why do you want the trace?
the profiler does a decent job of tracing, but it looks like it's a sampling profiler.
The trace that chrome gives me isn't helpful. I see mostly anonymous functions and stuff unrelated to what I'm trying to debug in my app. You're suggesting that if I postprocess it with a source map then maybe I can get what I want? I haven't considered that.
if there's a sourcemap, I think google chrome might do it for you
I'm still interested in generating a trace of my functions. I'm sorry if my first example was unclear or confusing. Hopefully the pseudocode example makes it clear what I'm trying to do.
I know Chrome does use sourcemaps with debugger
If you need full instrumentation, you can check out how cljs.spec does it, https://github.com/clojure/clojurescript/blob/r1.10.914/src/main/cljs/cljs/spec/test/alpha.cljc#L109-L167
looks pretty hairy
What is the easy way to import a JS module (it exports a JS class) to use inside cljs? Where should I put the JS file? Is not an NPM package and does not attach to window
. I’m using shadow-cljs if it helps
With shadow you declare js deps in a package.json. from there, check the shadow docs to match how the code is imported in js and against the shadow/cljs equivalent.
Thanks! For future references: https://shadow-cljs.github.io/docs/UsersGuide.html#classpath-js
Alright, so in cljc, these are equivalent:
(def b [0x72 0x65 0x6e 0x63 0x68])
#?(:clj (byte-array b) :cljs (js/Uint8Array. b))
They are equivalent in terms of both being collections of bytes. But they most likely provide you with differing APIs.
I should've been more clear - by their API I meant the fields/methods accessible via interop.
Java arrays should have things that all Java objects have. Same for JS objects, but those methods are different, plus UInt8Array
has a whole bunch of other methods.
It might or might not matter - impossible to say without the context.
Hello everyone! How can I use "export default" in cljs?
(:require ["lib-with-default$default" :as x])
and then x
in the code. assuming you mean using a npm library with a default export.
No I actually want to export a map from a file as default and then import it in another file.
I have come to know that I can ^:export to export but how to do it as default
So the file with the map is a CLJS file and the file that needs that map is a JS file?
nope both of the files are cljs files? please tell me if there is a workaround too
There's no workaround - your mindset is simply wrong about the problem.
Exporting as default is a JS construct, it doesn't exist in CLJS. If you have something like (def my-map {...})
in namespace a
and you need that map in namespace b
then all you have to do is add [a :refer [my-map]]
to the :require
list of the (ns ...)
form in the namespace b
. To avoid polluting namespace b
with all the new names that you require, you can require namespaces with aliases or with only their names.
So if you require [some.long.namespace.name]
, then you can use
. And if you require [some.long.namespace.name :as n]
, then you can use n/my-map
.
oh thank you very much, I am actually translating a react app and became a perfectionist in translating each and every construct.
That's alright, but I would retarget that perfectionism. :) From "it must be 100% as the original" to "it must behave in the same exact manner but be written the CLJS way". Otherwise, you'll be writing JS in CLJS, and that's a painful road.