Fork me on GitHub
#cljs-dev
<
2019-05-14
>
wilkerlucio03:05:32

hello, after some discussion in #clojurescript I think its worth to bring the discussion here, its about how to use JS libraries that depend on the JS native class system, currently there seems to be no way to extend on of those such classes and call its parent constructor (which is accessible via super in JS). This looks like a gap because makes very dificult to use those libraries with CLJS, is there some way to do it that I'm missing? or is there any plans on how we are going to handle this in the future? You can follow the original discussion from: https://clojurians.slack.com/archives/C03S1L9DN/p1557803014008100

dnolen13:05:03

@wilkerlucio far as I know ES6 classes can be decomposed into ES5 patterns

dnolen13:05:16

that said I've been thinking more about a defclass macro

dnolen13:05:58

but anyways, you should be able to inherit and call the parent prototype

dnolen13:05:26

there's tons of resources on the web about what ES6 classes look like in ES5 patterns

wilkerlucio13:05:28

@dnolen I hit a limitation wall I think, seems like there is no way to unwrap the super call when the class is defined with native class system, @lilactown also pointed an article talking about this https://clojurians.slack.com/archives/C03S1L9DN/p1557805806015700

wilkerlucio13:05:04

this is the gist of the problem:

dnolen13:05:17

@wilkerlucio I would read through this first and tell me what you think

wilkerlucio13:05:28

nice, that seems like an exit 🙂

dnolen13:05:39

I would like to see a lot more information before thinking about this more

dnolen13:05:49

if you feel like something is missing then write a JIRA w/ your research

dnolen13:05:53

and I will look over it carefully

wilkerlucio13:05:11

thanks for pointing the resource, I'll try following the tips there and see if I can get it to work

dnolen13:05:30

if you feel like the solution is suboptimal will still consider an enhancement

👍 1
wilkerlucio16:05:28

@dnolen I did some tries, but no suggested solution can fix the problem of calling a native class constructor, the only way I found to get around is falling back to writing the classes in JS and loading that back again in cljs, I did open the issue: https://dev.clojure.org/jira/browse/CLJS-3084

dnolen17:05:17

@wilkerlucio one thing we will have to consider is exactly how deep the support will be

dnolen17:05:02

FWIW I'm unlikely to spend anytime on this in the near future

dnolen17:05:09

there's too much to consider

dnolen17:05:20

so somebody needs to draw up a plan - and then we can assess that

dnolen17:05:52

also it's worth thinking about comparing to just writing this kind of stuff in JavaScript

dnolen17:05:09

whatever we would do in ClojureScript would effectively be a messy JavaScript thing

wilkerlucio17:05:39

yeah, that deserves some though, some way to make calling of super idiomatic, I can try start working out some syntax propositions and post in the ticket

dnolen17:05:21

I want to be clear that I'm not really interested in solving your specific problem

dnolen17:05:29

if we're going to do anything it should be a general solution

dnolen17:05:43

if the general solution is too wide a scope - then we're not going to do it

wilkerlucio17:05:48

sure, I understand, I'm just trying to think around this because that's the blocker, but I understand its about generic class generation

dnolen17:05:10

then feel free to propose something!

dnolen17:05:00

particularly interested in something idiomatic - perhaps with eye for what Clojure has already done etc.

👍 1