PaulLeCam / react-leaflet

React components for Leaflet maps
https://react-leaflet.js.org
Other
5.13k stars 884 forks source link

react-leaflet is not extendable #71

Closed uniphil closed 9 years ago

uniphil commented 9 years ago

When I npm install --save react-leaflet, I get a compiled version that does not include the src/ directory.

I'm using babel in my own project, so it would be nice to be able to do

import { Marker } from 'react-leaflet';

export default MyCustomizedMarker extends Marker {
  ...
}

My current solution is to add a github tarbal to package.json manually:

  "dependencies": {
    "react-leaflet": "https://github.com/PaulLeCam/react-leaflet/archive/v0.7.0"
  }

and then import like

import Marker from 'react-leaflet/src/Marker'

however, it would be nice to be able to do this with a normal npm install.

PaulLeCam commented 9 years ago

This is an issue with your compilation process, not this lib. See the babel-loader usage documentation for example if you are using Webpack, it explicitly excludes node_modules.

uniphil commented 9 years ago

No, the problem is that the src/ directory does not exist on npm install.

react-leaflet-no-src

PaulLeCam commented 9 years ago

This is not a problem, it is intended. The modules made to be consumed are in lib and are exposed by the public API.

uniphil commented 9 years ago

So to be clear, react-leaflet is not extendable by design, and

class CustomizedMarker extends Marker {

is not allowed.

If this is true, then react-leaflet is not for us. Just want to be clear before forking.

PaulLeCam commented 9 years ago

No, to be clear, there is nothing preventing you from extending the components as they are already exposed. It's just JavaScript.

uniphil commented 9 years ago

Hey, sorry for the tone of my previous messages. This library is an awesome step toward making great map apps, so thank you! I shouldn't jump on github issues before I have my morning coffee :smile:

The problem I was having with extending the components distributed in lib/ was.... I forgot to put lib/ in the import path haha.

I still want to make the case for one more reason to considering distributing with the src/ directory: when extending react-leaflet components, stack traces that lead into the react-leaflet uncompiled source are much nicer do dig through. Similar to how leaflet distributes leaflet-src.js. Any chance of it?

PaulLeCam commented 9 years ago

Hey, no problem. Sure, I'll publish the src folder as well in future npm releases.

uniphil commented 9 years ago

Awesome, thanks! :cake:

PaulLeCam commented 9 years ago

Added in RC3 :)