Fork me on GitHub
#cljs-dev
<
2018-11-27
>
bronsa00:11:27

@dnolen what is my best option for instantiating a deftype knowing its name at runtime?

bronsa00:11:27

i.e. the equivalent of clojure's (clojure.lang.Reflector/invokeConstructor (Class/forName "my-ns.type") args)

thheller01:11:17

you can't really look anything up dynamically given that :advanced will have renamed everything

mfikes01:11:20

If really pressed, perhaps you could export the positional factory functions for all deftypes you need in advance. That might work if you have a smallish closed set of them.

mfikes01:11:39

@bbrinck Since that error message work is rather large, I'm currently pursuing it in a branch, committing WIP as I go. It now has the :macro-syntax-check phase you pointed out. I'm thinking about trying to at least knock out a phase at a time to see where that leads. See https://gist.github.com/mfikes/cca647f962f38edb599596f8e7bffc43

💯 4
bronsa01:11:06

@thheller hm, maybe that's why I never implemented https://dev.clojure.org/jira/browse/TRDR-57 then

bronsa01:11:44

I remember looking into it when the initial port happened but I forgot the reason why that feature was not included

thheller01:11:49

yeah thats gonna be tough in an :advanced optimized build

bronsa01:11:13

not a terrible loss if we can't do it given that I've only gotten one request for it in 3 years I guess

thheller01:11:16

you could let the user register the contructors but thats about it

mfikes01:11:59

It might be nice to have static and/or REPL support for this (for dev-time), but users may then expect it to work everywhere...

bronsa01:11:12

aight, I'll decline that ticket then

👍 4
mfikes01:11:36

This ticket seems to explore other interesting ideas on the subject https://dev.clojure.org/jira/browse/CLJS-1328

thheller01:11:39

there really isn't anything you can do regarding this

mfikes01:11:02

Yeah, I can't see how to prevent defeating DCE

thheller01:11:29

as soon as you either export it or add a lookup table you lose DCE

darwin01:11:23

I believe, the lookup table could be exported into a var wrapped with (delay ...) this would get elided by DCE if no one referenced it, after requiring tools.reader or something else making use of it, then you would pay the price

thheller01:11:49

well I would not like giving up DCE as soon as tools.reader is used

bronsa01:11:15

that would not be ideal at all

darwin01:11:34

ok, just a quick idea

darwin02:11:09

I can imagine, it could be in a separate nameaspace, so people could require it on-demand

darwin02:11:21

and tools.reader would check for its presence via js interop

thheller02:11:19

I'd rather have the user register the reader manually if support is really required for them

thheller02:11:38

than destroying DCE if used incorrectly (which is already hard enough)

bronsa02:11:03

yeah, if we're requiring an explicit toggle then it doesn't improve much vs having users register ctors as tagged literals IMO

dnolen16:11:35

since tag registration is explicit - I wonder if this isn’t a good case for goog.reflect and a standard table for lookup

dnolen16:11:18

that said, given Transit, it’s not clear to me how popular EDN is anymore as a format

👆 4
bronsa17:11:55

well, I'd say that constructor literals are not usually used in data transfer

bronsa17:11:04

config files/code though

bronsa17:11:37

if you see a way for making this work let me know

bronsa17:11:54

afraid I don't know enough about goog.reflect/cljs advanced compilation to figure it out myself

richiardiandrea17:11:06

FWIW I finally did the split of special-doc-map to cljs.env - it took a while I know 😄