cljs-dev

ClojureScript compiler & std lib dev, https://clojurescript.org/community/dev
borkdude 2020-01-22T15:39:43.000900Z

(js->clj {:a 1} :keywordize-keys symbol)
{:a 1}
Making :keywordize-keys accept a function there seems an improvement. Open to patch?

borkdude 2020-01-22T15:43:16.001200Z

context:

#?(:cljs
   (do (def fs (let [m (js->clj (js/require "fs"))]
                 (zipmap (map symbol (keys m)) (vals m))))
       (deftest add-object-as-namespace
         (is (str/includes?
              (tu/eval* "(str (fs/readFileSync \"README.md\"))" {:namespaces {'fs fs}})
              "EPL")))))

2020-01-22T16:33:03.001700Z

then it wouldn’t be “keywordizing” though 🙃

2020-01-22T16:33:10.001900Z

“symbolizing” in your case

alexmiller 2020-01-22T16:38:17.002200Z

there is actually a ticket in CLJ for this

alexmiller 2020-01-22T16:38:39.002600Z

to break out the generic code here into a new more abstract function

alexmiller 2020-01-22T16:39:03.003Z

or sorry I'm thinking of clojure.walk stuff

alexmiller 2020-01-22T16:39:06.003200Z

but same problem

borkdude 2020-01-22T18:50:32.004700Z

@alexmiller for clojure.walk/keywordize-keys it's also a good idea

2020-01-22T19:02:26.005100Z

So do you not feel the name becomes wrong if you can configure it to arbitrary fn? I guess it could be just me being pedantic.

2020-01-22T19:02:49.005400Z

:keywordize-keys str

2020-01-22T19:03:04.005700Z

seems almost the opposite of what it was meant to do in a case like js->clj

2020-01-22T19:03:29.006200Z

I think more common is just key-fn as the option

2020-01-22T19:03:41.006500Z

like as in cheshire or I believe a few others

borkdude 2020-01-22T19:04:51.007200Z

I was actually remembering that cheshire had the same name, but apparently it uses a positional parameter for it. So maybe a new option :key-fn is less confusing

2020-01-22T19:06:48.007600Z

ah if it’s positional, perhaps I was thinking of some other lib

borkdude 2020-01-22T19:09:57.008400Z

a new option is also less likely to break existing code. what if someone passed a function as a truthy value and didn't care what function it was

2020-01-22T19:10:32.008600Z

ah sneaky

2020-01-22T19:15:08.009300Z

overall though, it does seem it could be useful to have the key fn be pluggable. however, is this already covered by this lib? https://github.com/mfikes/cljs-bean perhaps it is not pluggable there either (haven’t looked)

borkdude 2020-01-22T19:17:53.010Z

it has :prop->key and :key->prop

👍 1
borkdude 2020-01-22T19:18:40.010400Z

but I'm not sure if that's available in the js->clj equivalent

borkdude 2020-01-22T19:19:44.010600Z

seems it isn't

lilactown 2020-01-22T20:43:11.011200Z

a lot of my open source coding experience is writing and rewriting various versions of js->clj and clj->js

dnolen 2020-01-22T21:40:45.011800Z

@roman01la some nice runtime perf patches, thanks!

🙂 1
mfikes 2020-01-22T21:49:37.012800Z

@dnolen FWIW, I think we should fix https://clojure.atlassian.net/browse/CLJS-3205 before applying too many other patches (flying blind a little now) I may take a crack at if if I get a little time soon

dnolen 2020-01-22T21:51:11.013500Z

Oh that’s just because of the build scripts using http urls?

mfikes 2020-01-22T21:51:45.014Z

Maybe... something funky is also going on with Travis. I'm hoping it is the same and a trivial fix

dnolen 2020-01-22T21:52:11.014800Z

Ok I can audit the build scripts for any obvious things

mfikes 2020-01-22T21:52:16.015Z

Cool