Skip to content

Commit 8cb6939

Browse files
Remove lodash and use our own utils (google-map-react#535)
* Use pure reduce and map functions * Use only isEmpty from lodash * Create our own isEmpty, don't use lodash * Normalize utils names * Group utils together * Proper checking, better this way * Set default value to options
1 parent 22302fc commit 8cb6939

8 files changed

+32
-23
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
"jsdom": "^6.5.1",
8080
"kotatsu": "^0.14.0",
8181
"lint-staged": "^3.4.0",
82-
"lodash": "^4.13.1",
8382
"mocha": "^2.3.3",
8483
"node-sass": "^3.7.0",
8584
"normalize.css": "^4.1.1",

src/google_heatmap.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
import fp from 'lodash/fp';
2-
31
export const generateHeatmap = (instance, { positions }) =>
42
new instance.visualization.HeatmapLayer({
5-
data: fp.reduce(
3+
data: positions.reduce(
64
(acc, { lat, lng }) => {
75
acc.push({
86
location: new instance.LatLng(lat, lng),
97
});
108
return acc;
119
},
12-
[],
13-
positions
10+
[]
1411
),
1512
});
1613

17-
export const optionsHeatmap = (instance, { options }) =>
18-
fp.map(
19-
option => instance.set(option, options[option]),
20-
Object.keys(options || {})
21-
);
14+
export const optionsHeatmap = (instance, { options = {} }) =>
15+
Object.keys(options).map(option => instance.set(option, options[option]));

src/google_map.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,32 @@ import React, { Component } from 'react';
33
import PropTypes from 'prop-types';
44
import ReactDOM from 'react-dom';
55

6+
// libs
67
import shallowEqual from 'fbjs/lib/shallowEqual';
78

8-
import MarkerDispatcher from './marker_dispatcher';
9-
9+
// helpers
1010
import GoogleMapMap from './google_map_map';
11+
import MarkerDispatcher from './marker_dispatcher';
1112
import GoogleMapMarkers from './google_map_markers';
1213
import GoogleMapMarkersPrerender from './google_map_markers_prerender';
1314
import { generateHeatmap, optionsHeatmap } from './google_heatmap';
1415

15-
import googleMapLoader from './utils/loaders/google_map_loader';
16-
import detectBrowser from './utils/detect';
16+
// loaders
17+
import googleMapLoader from './loaders/google_map_loader';
1718

19+
// utils
1820
import Geo from './utils/geo';
19-
import isArraysEqualEps from './utils/array_helper';
20-
21-
import isPlainObject from './utils/is_plain_object';
22-
import pick from './utils/pick';
2321
import raf from './utils/raf';
22+
import pick from './utils/pick';
23+
import omit from './utils/omit';
2424
import log2 from './utils/math/log2';
25-
2625
import isNumber from './utils/isNumber';
27-
import omit from './utils/omit';
26+
import detectBrowser from './utils/detect';
27+
import isPlainObject from './utils/isPlainObject';
28+
import isArraysEqualEps from './utils/isArraysEqualEps';
2829
import detectElementResize from './utils/detectElementResize';
2930

31+
// consts
3032
const kEPS = 0.00001;
3133
const K_GOOGLE_TILE_SIZE = 256;
3234
// real minZoom calculated here _getMinZoom

src/utils/loaders/google_map_loader.js renamed to src/loaders/google_map_loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isEmpty } from 'lodash';
1+
import isEmpty from '../utils/isEmpty';
22

33
const BASE_URL = 'https://maps';
44
const DEFAULT_URL = `${BASE_URL}.googleapis.com`;
File renamed without changes.

src/utils/isEmpty.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const isEmpty = val => {
2+
// check for empty object {}, array []
3+
if (val !== null && typeof val === 'object') {
4+
if (Object.keys(val).length === 0) {
5+
return true;
6+
}
7+
} else if (val === null || val === undefined || val === '') {
8+
// check for undefined, null and ""
9+
return true;
10+
}
11+
return false;
12+
};
13+
14+
export default isEmpty;
File renamed without changes.

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3449,7 +3449,7 @@ lodash@^3.10.0, lodash@^3.10.1:
34493449
version "3.10.1"
34503450
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"
34513451

3452-
lodash@^4.0.0, lodash@^4.13.1, lodash@^4.17.4, lodash@^4.3.0, lodash@^4.6.1, lodash@~4.17.4:
3452+
lodash@^4.0.0, lodash@^4.17.4, lodash@^4.3.0, lodash@^4.6.1, lodash@~4.17.4:
34533453
version "4.17.4"
34543454
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
34553455

0 commit comments

Comments
 (0)