-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DraggableLinesHandler is missing methods when compiled to ES5 (with CRA) #2
Comments
I am using DraggableLinesHandler in production and don't have this problem. I'm also building using webpack, so I wouldn't expect my setup to be super different from yours. I could imagine that maybe the extension methods get tree-shaken away. Could you also try if it works with |
Thanks for the quick feedback! That's a good idea, I'll also try that. Meanwhile, I've managed to narrow the issue down further: The following class works, i.e. calling "myMethod" works even in production: class MyHandler extends Handler {
constructor(map: LeafletMap) {
super(map);
console.debug("MyHandler");
}
myMethod() {
console.debug("myMethod");
}
} However, when I add Object.assign(MyHandler.prototype, Evented.prototype); the method "disappears" in production, just like with DraggableLines. Tree-shaking was one of my suspects as well, maybe overwriting stuff on the prototype makes webpack/babel lose track of what methods are used and tree-shake too much 🤔 |
So, I've been diving deeper into the compiled code, and I think I've now figured out what exactly goes wrong (or rather why the
So for some reason, the prototype augmentation seems to fall down when compiling to ES5. This is all I have time for today, next time I'll try compiling with DraggableLines v1.0.11 as you suggested :) |
That looks quite complex, I would have to dig into the code to really understand what's going on. But it somehow seems like the ES5 transpiler is wrapping the constructor in another function, so we are assigning the methods to the prototype of the wrapper, which does not affect the created objects. I guess that |
Sure thing, there's no rush for this :) One thing that might be interesting: Leaflet's offers a If you put together any prototype of an alternative approach, I'd be happy to help test it :) |
I have released a new version where I used a different multi-inheritance mechanism. Could you check if that fixes the issue for you? |
Feel free to reopen this if the issue persists. |
Hey there,
thanks for this neat library, I was super happy to find this functionality as a plugin for Leaflet :)
I've been using DraggableLines in a React project, and thought all was fine, but recently I noticed that in the production build it broke at a place where I use
DraggableLinesHandler.enableForLayer()
anddisableForLayer()
to switch it on and off.I don't expect you to fully support all scenarios, and I'm not even sure if this is a problem your code or somewhere else, but I thought I'd report this just in case someone else has a similar issue.
First of all, some relevant package versions (taken from my yarn.lock):
The related issue in my project is: lehnerpat/train-ride-maps#20
Now, for some more details:
enableForLayer()
method on a DraggableLines instance, I get the error:disableForLayer()
t.draggableLines
) doesn't have any of the methods implemented in DraggableLinesHandler; it only has the method of Leaflet's stock Handler.I'm continuing to investigate this, partly because DraggableLines really fits my use case and I'd prefer not to implement this myself, and partly because I know what is going wrong here exactly.
One hypothesis I have is that mixing the ES6/TS class-based inheritance you use in DraggableLinesHandler with Leaflet's custom-built class system somehow confuses the Babel transpiler or something.
I'm planning to test this by adding another simple subclass of Handler in my own code, and see if it shows the same behavior, and then possibly also trying to change DraggableLinesHandler to use
L.Class.extend()
instead of ES6 classes.If you have any ideas or insights, I'd be happy to hear them :)
I'll report here if I find anything significant.
The text was updated successfully, but these errors were encountered: