Skip to content
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

Big dependency and dev environment cleanup #1119

Merged
merged 8 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"mourner",
"plugin:import/recommended"
],
"parser": "babel-eslint",
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
"sourceType": "module",
"requireConfigFile": false
},
"plugins": [
"import"
Expand Down
4 changes: 2 additions & 2 deletions bench/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<link href='https://www.mapbox.com/base/latest/base.css' rel='stylesheet' />
<link rel='stylesheet' href='/node_modules/mapbox-gl/dist/mapbox-gl.css'/>
<link rel='stylesheet' href='https://api.mapbox.com/mapbox-gl-js/v2.10.0/mapbox-gl.css'/>
<link rel='stylesheet' href='/dist/mapbox-gl-draw.css'/>

<style>
Expand Down Expand Up @@ -47,7 +47,7 @@
<div id="map"></div>
<div id="tests"></div>
<div id="logs"></div>
<script src="/node_modules/mapbox-gl/dist/mapbox-gl.js"></script>
<script src="https://api.mapbox.com/mapbox-gl-js/v2.10.0/mapbox-gl.js"></script>
<script src="/dist/mapbox-gl-draw-unminified.js"></script>
<script src="/dist/bench.js"></script>
</body>
Expand Down
27 changes: 27 additions & 0 deletions bench/lib/evented.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

export default class Evented {
on(type, listener) {
this._listeners = this._listeners || {};
this._listeners[type] = this._listeners[type] || [];
this._listeners[type].push(listener);
return this;
}

off(type, listener) {
if (!this._listeners) return this;
const listeners = this._listeners[type];
if (!listeners) return this;
const index = listeners.indexOf(listener);
if (index !== -1) listeners.splice(index, 1);
return this;
}

fire(type, data) {
if (!this._listeners) return this;
const listeners = this._listeners[type];
if (!this._listeners[type]) return;
for (const listener of listeners) {
listener.call(this, data);
}
}
}
15 changes: 7 additions & 8 deletions bench/lib/mouse_drag.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import mouseEvents from './mouse_events'
import mousePath from './mouse_path'
import mouseEvents from './mouse_events';
import mousePath from './mouse_path';

export default function(start, map) {

var path = mousePath(start);

var events = mouseEvents(map);
const path = mousePath(start);
const events = mouseEvents(map);

events.push('mousedown', {
x: start.x,
y: start.y
}, true);

for (var i=0; i<path.length; i++) {
for (let i = 0; i < path.length; i++) {
events.push('mousemove', path[i]);
}
for (var i=path.length-1; i>=0; i--) {
for (let i = path.length - 1; i >= 0; i--) {
events.push('mousemove', path[i]);
}

Expand All @@ -26,5 +25,5 @@ export default function(start, map) {

return function(cb) {
events.run(cb);
}
};
}
15 changes: 7 additions & 8 deletions bench/lib/mouse_trace.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import mouseEvents from './mouse_events'
import mouseEvents from './mouse_events';

export default function(ring, map) {

var events = mouseEvents(map);
const events = mouseEvents(map);

var lastPoint = null;
let lastPoint = null;

for (var c=0; c<ring.length; c++) {
var coord = ring[c];
var point = map.project({
for (let c = 0; c < ring.length; c++) {
const coord = ring[c];
const point = map.project({
lng: coord[0],
lat: coord[1]
});
Expand All @@ -26,6 +26,5 @@ export default function(ring, map) {

return function(cb) {
events.run(cb);
}

};
}
33 changes: 17 additions & 16 deletions bench/lib/trace_progress.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
export default function(features, map) {
var sizes = [];
var total = 0;
features.forEach(feature => {
feature.geometry.coordinates.forEach(ring => {
const sizes = [];
let total = 0;
for (const feature of features) {
for (const ring of feature.geometry.coordinates) {
sizes.push(ring.length);
total += ring.length;
});
});
}
}

var progressDiv = document.getElementById('progress');
const progressDiv = document.getElementById('progress');

var one = 100/total;
for (var i=0; i<sizes.length; i++) {
sizes[i] = one*sizes[i];
const one = 100 / total;
for (let i = 0; i < sizes.length; i++) {
sizes[i] = one * sizes[i];
}

var pos = 0;
var lastDone = -1;
map.on('progress', function(e) {
let pos = 0;
let lastDone = -1;

map.on('progress', (e) => {
if (e.done < lastDone) {
pos++;
}
lastDone = e.done;
var done = 0;
for (var i=0; i<pos; i++) {
let done = 0;
for (let i = 0; i < pos; i++) {
done += sizes[i];
}
done += (sizes[pos] * e.done / 100);
progressDiv.style.width = done+"%";
progressDiv.style.width = `${done}%`;
});
}
24 changes: 2 additions & 22 deletions bench/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@

import flowRemoveTypes from '@mapbox/flow-remove-types';
import replace from '@rollup/plugin-replace';
import json from '@rollup/plugin-json';
import buble from '@rollup/plugin-buble';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';

// Using this instead of rollup-plugin-flow due to
// https://github.com/leebyron/rollup-plugin-flow/issues/5
function flow() {
return {
name: 'flow-remove-types',
transform: code => ({
code: flowRemoveTypes(code).toString(),
map: null
})
};
}
import commonjs from '@rollup/plugin-commonjs';

export default {
input: ['bench/index.js'],
Expand All @@ -27,21 +14,14 @@ export default {
indent: false
},
treeshake: true,
external: [
// geojsonlint-lines has a main function that requires the path and fs module.
// We never call it.
'fs',
'path'
],
plugins: [
flow(),
json(),
replace({
'process.env.MapboxAccessToken': JSON.stringify(process.env.MapboxAccessToken),
'process.env.MAPBOX_ACCESS_TOKEN': JSON.stringify(process.env.MAPBOX_ACCESS_TOKEN),
preventAssignment: true
}),
buble({transforms: {dangerousForOf: true}, objectAssign: "Object.assign"}),
false,
resolve({
browser: true,
preferBuiltins: false
Expand Down
2 changes: 1 addition & 1 deletion bench/tests/direct_select_large.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import {Evented} from 'mapbox-gl/src/util/evented';
import Evented from '../lib/evented';
import SouthAmerica from '../fixtures/south-america.json';
import formatNumber from '../lib/format_number';
import fpsRunner from '../lib/fps';
Expand Down
2 changes: 1 addition & 1 deletion bench/tests/direct_select_large_zoomed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import {Evented} from 'mapbox-gl/src/util/evented';
import Evented from '../lib/evented';
import SouthAmerica from '../fixtures/south-america.json';
import formatNumber from '../lib/format_number';
import fpsRunner from '../lib/fps';
Expand Down
2 changes: 1 addition & 1 deletion bench/tests/direct_select_small.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import {Evented} from 'mapbox-gl/src/util/evented';
import Evented from '../lib/evented';
import SouthAmerica from '../fixtures/south-america.json';
import formatNumber from '../lib/format_number';
import fpsRunner from '../lib/fps';
Expand Down
2 changes: 1 addition & 1 deletion bench/tests/direct_select_small_zoomed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import {Evented} from 'mapbox-gl/src/util/evented';
import Evented from '../lib/evented';
import SouthAmerica from '../fixtures/south-america.json';
import formatNumber from '../lib/format_number';
import fpsRunner from '../lib/fps';
Expand Down
2 changes: 1 addition & 1 deletion bench/tests/draw_land_polygon_large.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import {Evented} from 'mapbox-gl/src/util/evented';
import Evented from '../lib/evented';
import formatNumber from '../lib/format_number';
import land from '../fixtures/land.json';
import fpsRunner from '../lib/fps';
Expand Down
2 changes: 1 addition & 1 deletion bench/tests/draw_land_polygon_small.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import {Evented} from 'mapbox-gl/src/util/evented';
import Evented from '../lib/evented';
import formatNumber from '../lib/format_number';
import land from '../fixtures/land.json';
import fpsRunner from '../lib/fps';
Expand Down
2 changes: 1 addition & 1 deletion bench/tests/draw_line_string_large.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import {Evented} from 'mapbox-gl/src/util/evented';
import Evented from '../lib/evented';
import formatNumber from '../lib/format_number';
import fpsRunner from '../lib/fps';
import DrawMouse from '../lib/mouse_draw';
Expand Down
2 changes: 1 addition & 1 deletion bench/tests/draw_line_string_large_zoomed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import {Evented} from 'mapbox-gl/src/util/evented';
import Evented from '../lib/evented';
import formatNumber from '../lib/format_number';
import fpsRunner from '../lib/fps';
import DrawMouse from '../lib/mouse_draw';
Expand Down
2 changes: 1 addition & 1 deletion bench/tests/draw_line_string_small.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import {Evented} from 'mapbox-gl/src/util/evented';
import Evented from '../lib/evented';
import formatNumber from '../lib/format_number';
import fpsRunner from '../lib/fps';
import DrawMouse from '../lib/mouse_draw';
Expand Down
2 changes: 1 addition & 1 deletion bench/tests/draw_point_large.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import {Evented} from 'mapbox-gl/src/util/evented';
import Evented from '../lib/evented';
import formatNumber from '../lib/format_number';
import fpsRunner from '../lib/fps';
import DrawMouse from '../lib/mouse_draw';
Expand Down
2 changes: 1 addition & 1 deletion bench/tests/draw_point_large_zoomed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import {Evented} from 'mapbox-gl/src/util/evented';
import Evented from '../lib/evented';
import formatNumber from '../lib/format_number';
import fpsRunner from '../lib/fps';
import DrawMouse from '../lib/mouse_draw';
Expand Down
2 changes: 1 addition & 1 deletion bench/tests/draw_point_small.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import {Evented} from 'mapbox-gl/src/util/evented';
import Evented from '../lib/evented';
import formatNumber from '../lib/format_number';
import fpsRunner from '../lib/fps';
import DrawMouse from '../lib/mouse_draw';
Expand Down
2 changes: 1 addition & 1 deletion bench/tests/draw_polygon_large.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import {Evented} from 'mapbox-gl/src/util/evented';
import Evented from '../lib/evented';
import formatNumber from '../lib/format_number';
import fpsRunner from '../lib/fps';
import DrawMouse from '../lib/mouse_draw';
Expand Down
2 changes: 1 addition & 1 deletion bench/tests/draw_polygon_large_zoomed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import {Evented} from 'mapbox-gl/src/util/evented';
import Evented from '../lib/evented';
import formatNumber from '../lib/format_number';
import fpsRunner from '../lib/fps';
import DrawMouse from '../lib/mouse_draw';
Expand Down
2 changes: 1 addition & 1 deletion bench/tests/draw_polygon_small.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import {Evented} from 'mapbox-gl/src/util/evented';
import Evented from '../lib/evented';
import formatNumber from '../lib/format_number';
import fpsRunner from '../lib/fps';
import DrawMouse from '../lib/mouse_draw';
Expand Down
2 changes: 1 addition & 1 deletion bench/tests/draw_urban_areas_polygon_large.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import {Evented} from 'mapbox-gl/src/util/evented';
import Evented from '../lib/evented';
import formatNumber from '../lib/format_number';
import land from '../fixtures/urban_areas.json';
import fpsRunner from '../lib/fps';
Expand Down
2 changes: 1 addition & 1 deletion bench/tests/draw_urban_areas_polygon_small.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import {Evented} from 'mapbox-gl/src/util/evented';
import Evented from '../lib/evented';
import formatNumber from '../lib/format_number';
import land from '../fixtures/urban_areas.json';
import fpsRunner from '../lib/fps';
Expand Down
2 changes: 1 addition & 1 deletion bench/tests/simple_select_large.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import {Evented} from 'mapbox-gl/src/util/evented';
import Evented from '../lib/evented';
import SouthAmerica from '../fixtures/south-america.json';
import formatNumber from '../lib/format_number';
import fpsRunner from '../lib/fps';
Expand Down
2 changes: 1 addition & 1 deletion bench/tests/simple_select_large_two_maps.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import {Evented} from 'mapbox-gl/src/util/evented';
import Evented from '../lib/evented';
import SouthAmerica from '../fixtures/south-america.json';
import formatNumber from '../lib/format_number';
import fpsRunner from '../lib/fps';
Expand Down
2 changes: 1 addition & 1 deletion bench/tests/simple_select_large_zoomed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import {Evented} from 'mapbox-gl/src/util/evented';
import Evented from '../lib/evented';
import SouthAmerica from '../fixtures/south-america.json';
import formatNumber from '../lib/format_number';
import fpsRunner from '../lib/fps';
Expand Down
2 changes: 1 addition & 1 deletion bench/tests/simple_select_small.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import {Evented} from 'mapbox-gl/src/util/evented';
import Evented from '../lib/evented';
import SouthAmerica from '../fixtures/south-america.json';
import formatNumber from '../lib/format_number';
import fpsRunner from '../lib/fps';
Expand Down
Loading