mapbox-gl-draw icon indicating copy to clipboard operation
mapbox-gl-draw copied to clipboard

Importing internal dependencies

Open thiagoxvo opened this issue 7 years ago • 5 comments

I am creating a new drawing mode. To avoid reinventing the wheel I would like to reuse some functions that were already implemented in:


@mapbox/mapbox-gl-draw/src/lib/common_selectors
@mapbox/mapbox-gl-draw/src/lib/double_click_zoom

I am using create-react-app and if I try to import any of them and build my project, I have the minification issue:

Failed to minify the code from this file:
    ./node_modules/@mapbox/mapbox-gl-draw/src/lib/double_click_zoom.js:2

I am using: mapbox-gl-js 0.44.2: mapbox-gl-draw 1.0.7:

I could send a PR if I get a better understanding how to solve this.

thiagoxvo avatar May 11 '18 15:05 thiagoxvo

@thiagoxvo - To do this well, I think we need to expose these via the mode_interface. Currently all of the logic filled mode_interface functions are added to the interface via mode_interface_accessors.

I'd love to see a PR that moves common_selectors onto the mode_interface via a mode_interface_selectors file or something.

This same practice can be used for double_click_zoom.

mcwhittemore avatar May 11 '18 15:05 mcwhittemore

I didn't know about this mode_interface 🤔, should I be using this to create my modes? I try to follow the other custom modes also the built-in modes and none of them use this mode_interface as a base mode.

thiagoxvo avatar May 11 '18 15:05 thiagoxvo

What do you mean by exposing would be something like this?

const CommonSelectors = require('../lib/common_selectors');
ModeInterface.prototype.isVertex = function(e) {
  return CommonSelectors.isVertex(e)
};

// and later on I would be using this way ??
import MapboxDraw from '@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw'

const MyAwesomeMode = MapboxDraw.modes.mode_interface
// and than I can call...
MyAwesomeMode.isVertex()

thiagoxvo avatar May 11 '18 16:05 thiagoxvo

I don't think there is any reason to expose them via the mode_interface. The library functions don't need to access this of the mode (or they take it in as a parameter if they need it), so they can just be exported normally. I created #974 which does this. Then you can just do this in your custom mode:

import MapboxGLDraw, { CommonSelectors, doubleClickZoom } from '@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw'

trygveaa avatar Mar 20 '20 16:03 trygveaa

Any updates?

PendaGTP avatar Mar 12 '24 16:03 PendaGTP