Skip to content

refactor: make lodash a devDependency #930

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
"can-use-dom": "^0.1.0",
"google-maps-infobox": "^2.0.0",
"invariant": "^2.2.1",
"lodash": "^4.16.2",
"marker-clusterer-plus": "^2.1.4",
"markerwithlabel": "^2.0.1",
"prop-types": "^15.5.8",
Expand Down Expand Up @@ -139,6 +138,7 @@
"isomorphic-fetch": "^2.2.1",
"jscodeshift": "^0.3.32",
"lint-staged": "^6.0.0",
"lodash": "^4.16.2",
"make-fetch-happen": "^2.6.0",
"mkdirp": "^0.5.1",
"prettier": "^1.8.2",
Expand Down
13 changes: 6 additions & 7 deletions src/macros/OverlayView.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* global google */
import _ from "lodash"
import invariant from "invariant"
import React from "react"
import ReactDOM from "react-dom"
Expand Down Expand Up @@ -69,10 +68,10 @@ export class OverlayView extends React.PureComponent {
super(props, context)
const overlayView = new google.maps.OverlayView()
// You must implement three methods: onAdd(), draw(), and onRemove().
overlayView.onAdd = _.bind(this.onAdd, this)
overlayView.draw = _.bind(this.draw, this)
overlayView.onRemove = _.bind(this.onRemove, this)
this.onPositionElement = _.bind(this.onPositionElement, this)
overlayView.onAdd = this.onAdd.bind(this)
overlayView.draw = this.draw.bind(this)
overlayView.onRemove = this.onRemove.bind(this)
this.onPositionElement = this.onPositionElement.bind(this)
// You must call setMap() with a valid Map object to trigger the call to
// the onAdd() method and setMap(null) in order to trigger the onRemove() method.
overlayView.setMap(this.context[MAP])
Expand Down Expand Up @@ -119,7 +118,7 @@ export class OverlayView extends React.PureComponent {
offset,
this.props
)
_.assign(this.containerElement.style, layoutStyles)
Object.assign(this.containerElement.style, layoutStyles)
}

onRemove() {
Expand All @@ -140,7 +139,7 @@ export class OverlayView extends React.PureComponent {
updaterMap,
prevProps
)
_.delay(this.state[OVERLAY_VIEW].draw)
setImmediate(this.state[OVERLAY_VIEW].draw)
}

componentWillUnmount() {
Expand Down
9 changes: 5 additions & 4 deletions src/macros/places/SearchBox.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* global google */
import _ from "lodash"
import invariant from "invariant"
import canUseDOM from "can-use-dom"
import React from "react"
Expand Down Expand Up @@ -110,7 +109,7 @@ export class SearchBox extends React.PureComponent {
* @see https://developers.google.com/maps/documentation/javascript/3.exp/reference#SearchBox
*/
const searchBox = new google.maps.places.SearchBox(
this.containerElement.querySelector('input')
this.containerElement.querySelector("input")
)
construct(SearchBox.propTypes, updaterMap, this.props, searchBox)
this.setState({
Expand Down Expand Up @@ -145,7 +144,7 @@ export class SearchBox extends React.PureComponent {
const child = this.context[MAP].controls[
this.props.controlPosition
].removeAt(this.mountControlIndex)
if(child !== undefined){
if (child !== undefined) {
this.containerElement.appendChild(child)
}
}
Expand All @@ -164,7 +163,9 @@ export class SearchBox extends React.PureComponent {

export default SearchBox

const isValidControlPosition = _.isNumber
const isValidControlPosition = function(value) {
return typeof value === "number"
}

const eventMap = {}

Expand Down
44 changes: 27 additions & 17 deletions src/utils/MapChildHelper.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
/* global google */
/* eslint-disable no-param-reassign */
import _ from "lodash"

const lowerFirst = s => s.substring(0, 1).toLowerCase() + s.substring(1)
const reduceMap = (map, reducer, initial) => {
let result = initial
for (const key of Object.keys(map)) {
result = reducer(result, map[key], key)
}
return result
}

function rdcUncontrolledAndControlledProps(acc, value, key) {
if (_.has(acc.prevProps, key)) {
if (typeof acc.prevProps[key] !== "undefined") {
const match = key.match(/^default(\S+)/)
if (match) {
const unprefixedKey = _.lowerFirst(match[1])
if (!_.has(acc.nextProps, unprefixedKey)) {
const unprefixedKey = lowerFirst(match[1])
if (typeof acc.nextProps[unprefixedKey] === "undefined") {
acc.nextProps[unprefixedKey] = acc.prevProps[key]
}
} else {
Expand All @@ -18,7 +26,8 @@ function rdcUncontrolledAndControlledProps(acc, value, key) {
}

function applyUpdaterToNextProps(updaterMap, prevProps, nextProps, instance) {
_.forEach(updaterMap, (fn, key) => {
Object.keys(updaterMap).forEach(key => {
const fn = updaterMap[key]
const nextValue = nextProps[key]
if (nextValue !== prevProps[key]) {
fn(instance, nextValue)
Expand All @@ -27,10 +36,14 @@ function applyUpdaterToNextProps(updaterMap, prevProps, nextProps, instance) {
}

export function construct(propTypes, updaterMap, prevProps, instance) {
const { nextProps } = _.reduce(propTypes, rdcUncontrolledAndControlledProps, {
nextProps: {},
prevProps,
})
const { nextProps } = reduceMap(
propTypes,
rdcUncontrolledAndControlledProps,
{
nextProps: {},
prevProps,
}
)
applyUpdaterToNextProps(
updaterMap,
{
Expand Down Expand Up @@ -62,10 +75,10 @@ export function componentWillUnmount(component) {
}

function registerEvents(component, instance, eventMap) {
const registeredList = _.reduce(
const registeredList = reduceMap(
eventMap,
(acc, googleEventName, onEventName) => {
if (_.isFunction(component.props[onEventName])) {
if (typeof component.props[onEventName] === "function") {
acc.push(
google.maps.event.addListener(
instance,
Expand All @@ -79,12 +92,9 @@ function registerEvents(component, instance, eventMap) {
[]
)

component.unregisterAllEvents = _.bind(
_.forEach,
null,
registeredList,
unregisterEvent
)
component.unregisterAllEvents = () => {
registeredList.forEach(registered => unregisterEvent(registered))
}
}

function unregisterEvent(registered) {
Expand Down
3 changes: 1 addition & 2 deletions src/utils/OverlayViewHelper.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/* global google */
import _ from "lodash"

export function getOffsetOverride(containerElement, props) {
const { getPixelPositionOffset } = props
//
// Allows the component to control the visual position of the OverlayView
// relative to the LatLng pixel position.
//
if (_.isFunction(getPixelPositionOffset)) {
if (typeof getPixelPositionOffset === "function") {
return getPixelPositionOffset(
containerElement.offsetWidth,
containerElement.offsetHeight
Expand Down
3 changes: 1 addition & 2 deletions src/withGoogleMap.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* global google */
import _ from "lodash"
import warning from "warning"
import invariant from "invariant"
import { getDisplayName } from "recompose"
Expand All @@ -26,7 +25,7 @@ export function withGoogleMap(BaseComponent) {
map: null,
}

handleComponentMount = _.bind(this.handleComponentMount, this)
handleComponentMount = this.handleComponentMount.bind(this)

getChildContext() {
return {
Expand Down
3 changes: 1 addition & 2 deletions src/withScriptjs.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import _ from "lodash"
import invariant from "invariant"
import canUseDOM from "can-use-dom"
import { getDisplayName } from "recompose"
Expand Down Expand Up @@ -26,7 +25,7 @@ export function withScriptjs(BaseComponent) {

isUnmounted = false

handleLoaded = _.bind(this.handleLoaded, this)
handleLoaded = this.handleLoaded.bind(this)

handleLoaded() {
if (this.isUnmounted) {
Expand Down