Fork me on GitHub
#cljs-dev
<
2020-01-22
>
borkdude15:01:43

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

borkdude15:01:16

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")))))

mikerod16:01:03

then it wouldn’t be “keywordizing” though 🙃

mikerod16:01:10

“symbolizing” in your case

Alex Miller (Clojure team)16:01:17

there is actually a ticket in CLJ for this

Alex Miller (Clojure team)16:01:39

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

Alex Miller (Clojure team)16:01:03

or sorry I'm thinking of clojure.walk stuff

borkdude18:01:32

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

mikerod19:01:26

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.

mikerod19:01:49

:keywordize-keys str

mikerod19:01:04

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

mikerod19:01:29

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

mikerod19:01:41

like as in cheshire or I believe a few others

borkdude19:01:51

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

mikerod19:01:48

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

borkdude19:01:57

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

mikerod19:01:08

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)

borkdude19:01:53

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

👍 4
borkdude19:01:40

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

borkdude19:01:44

seems it isn't

lilactown20:01:11

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

dnolen21:01:45

@roman01la some nice runtime perf patches, thanks!

🙂 4
mfikes21:01:37

@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

dnolen21:01:11

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

mfikes21:01:45

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

dnolen21:01:11

Ok I can audit the build scripts for any obvious things