This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-30
Channels
- # babashka (18)
- # beginners (90)
- # calva (33)
- # clara (6)
- # cljfx (11)
- # cljs-dev (22)
- # cljsrn (9)
- # clojure (71)
- # clojure-australia (2)
- # clojure-czech (15)
- # clojure-europe (27)
- # clojure-germany (9)
- # clojure-nl (4)
- # clojure-serbia (3)
- # clojure-uk (10)
- # clojurescript (17)
- # conjure (12)
- # data-oriented-programming (2)
- # deps-new (6)
- # fulcro (29)
- # graphql (10)
- # hugsql (6)
- # jobs (1)
- # lsp (59)
- # malli (8)
- # off-topic (76)
- # pathom (15)
- # polylith (130)
- # re-frame (9)
- # reagent (15)
- # releases (4)
- # rewrite-clj (6)
- # ring (6)
- # rum (9)
- # shadow-cljs (116)
- # specter (5)
- # testing (7)
- # tools-deps (24)
- # vim (6)
- # xtdb (17)
In Brave, I see a warning now regarding SharedArrayBuffer
and it looks like it originates from something like shadow$provide.module$node_modules$scheduler$cjs$scheduler_development
.
@pmooser that is a library you are using, or rather that react is using. I have no control over that and shadow-cljs is not involved in that.
is there a way to get custom formatters and/or a CLJS REPL in Chrome devtools when using shadow-cljs?
Maybe not exactly what you want, but if you want to make your Chrome devtools more CLJS friendly you might check out Dirac: https://github.com/binaryage/dirac
I haven't personally used it (honestly, I've just been too lazy to set it up), but I've heard a lot of praise for it in the community
Does Dirac work with shadow-cljs?
It should work with any Clojurescript code running in a browser. Shadow-cljs is just a build system.
@U05224H0W can you confirm this?
no. dirac does not work. or it didn't use to work, it has been a while since I looked.
okay thanks 🙂
alright, thanks
i'm seeing some strange compiler output
(defn js-i18n [format-string-string & args]
(js* "ttag/t`~{}`" format-string-string)
(apply ttag/t (-> format-string-string chomp-format-string into-array) args))
i'm playing around with emitting a tagged format literal in js for our i18n. And strangely, this is emitting
(metabase.shared.util.i18n.js_i18n.cljs$core$IFn$_invoke$arity$variadic = (function (format_string_string,args){
ttag/t`format_string_string`;
return cljs.core.apply.cljs$core$IFn$_invoke$arity$3(shadow.js.shim.module$ttag.t,cljs.core.into_array.cljs$core$IFn$_invoke$arity$1(metabase.shared.util.i18n.chomp_format_string(format_string_string)),args);
}));
which is including the name of the var, not its contents: ttag/t'format_string_string'
(had to use apostrophes instead of backticks here).
however, evaluating (js* "1 + ~{}" x)
at a repl where x is (def x 3)
correctly yeilds 4. So it seems to resolve at runtime in a repl but under advanced compilation uses the local nameoh i see. i was thinking it would end up as 1 + 3
instead of 1 + x
with that being a valid local
i'm fighting against an i18n library that has a plugin to enumerate all strings for translation that looks for tagged template literals. and i'm working on how i can get some cljs code to play nice with that
it would need to use that since the compiler otherwise isn't currently able to emit those
awesome. thanks for your help and sorry for the wall of text for a really dumb question 🙂
yeah. and since they are callable as functions its not a big hindrance. just a bummer that their plugin to find them looks over the ast for tagged literals in particular
@dpsutton https://github.com/thheller/shadow-cljs/commit/e043d5be60877bd1d367080a9a41fc9d12364b91 😉
need to finish up some more testing with new CLJS version and then that'll be in the next release
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates
myTag`That ${ person } is a ${ age }.`;
is equivalent to
myTag(["That ", " is a "], person, age)
yeah its confusing at first but then just totally makes sense mechanically. it's just chopped up
hmm wonder if that should be (js-template foo "bar")
or (js-tagged-template foo "bar")
as in a separate form or just handled by being smart and checking the first argument 😛
https://github.com/thheller/shadow-cljs/commit/109ea8858b5180522895b1d32c17e47d8cfff90e
dunno if this is actually useful but it has been bugging me that this wasn't supported for a while 😛
probably full of bugs still, pretty sure the escape logic is too naive but who knows 😉
yeah that looks closer. feels weird to emit without munging. i think you could define your own functions in cljs so it should probably be munged
(js-template (function-that-is-called-with-template-arg) "foo")
is
function_that_is_called_with_template_arg()`foo
`it isn't taking the literal symbol and just dumps it there. it is actually analyzing that symbol
I mean for your stuff you likely still need a macro either way if you just want to emit that as a side effect so the parser can find it?
it needs to parse the compiled output to compile a list of strings needing translations
yeah but depends on what it is looking for I guess. dunno if it understands the aliasing shadow-cljs does for modules and stuff
yeah i was looking at that. i think that would be another problem to solve but it felt more approachable. was wondering what your shim was and how wrapped over the underlying lib it was
you appear to be using :npm-module
so if you have (:require ["ttag" :refer (t)])
and (js-template t "foo")
what would give you
shadow.js.shim.module$ttag = require("ttag");
shadow.js.shim.module$ttag.t`foo
`thinking about it a macro may actually be enough with a bit of js*
, doesn't need to do all I'm doing now
I pushed 2.12.0
(minor bump because of new cljs version) which also has the (js-template ...)
if you want to try that
i'm on 2.12.0: shadow-cljs - server version: 2.12.0 running at
, and (js-template ttag/t "hello")
is giving me an error about an undeclared var js-template
getting an error with (js-template ttag/t "hello")
and similarly with just a base test: (js-template "hello")
: cannot read property call of undefined
nevermind, must have been some funky repl state. re-evaled the ns with the require and it is now working
I expect there to be bugs with this. I didn't test is very much and the implementation is definitely kinda rushed in a late night sleepy state 🙂
once this has been tested a little more we can maybe make a patch for CLJS out of it
one thing to think about, is that tagged template literals, and template literals in general, make the most sense when they can have the interpolated values. i tried a simple (js-template "hello ${\"there\"}")
and it emitted t'hello \$"there"' which was almost workable. not sure how to handle this. off the cuff might be (js-template "hello " x)
might emit t'hello ${x}'
but i doubt that might be worth the trouble and sounds like a super uphill battle going into cljs
(js-template "hello " (any-cljs "expr"))
is totally valid, if it was using ${}
then you'd run into all sorts of annoying quoting issues
a difficult part for this particular implementation is that the translation library expects "your {x} works perfectly"
and will expect the translated phrase to be "your {placeholder} works perfectly" and i can't recreate that in this guise
(js-template "your " x " works pefectly")
would emit the "works pefectly" as part of the substitution rather than the base phrase
again, certainly a quirk in this implementation but kinda the point of the templates i think
it may just be the CLJS compiler emitting the usual extra ()
which I can't do anything about unfortunately
var x_46339 = "soundcard";
(metabase.shared.util.i18n.js_template.cljs$core$IFn$_invoke$arity$3 ? metabase.shared.util.i18n.js_template.cljs$core$IFn$_invoke$arity$3("your ",x_46339," works pefectly") : metabase.shared.util.i18n.js_template.call(null,"your ",x_46339," works pefectly"));
that is definitely not the correct output. this is not using the special form at all
and the plan would be to move that into cljs proper as a special form with those methods for analyzing and emitting?
well it definitely needs more discussion and testing before this can be submitted to CLJS proper