-
Notifications
You must be signed in to change notification settings - Fork 939
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(drawing/DrawingManager): revamp with jscodeshift
- Loading branch information
Showing
4 changed files
with
95 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import warning from "warning" | ||
|
||
warning( | ||
false, | ||
`[DEPRECATED] "react-google-maps/lib/drawing/DrawingManager" has been moved to "react-google-maps/lib/components/drawing/DrawingManager".` | ||
) | ||
|
||
export { default } from "../components/drawing/DrawingManager" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* global google */ | ||
import invariant from "invariant" | ||
import React from "react" | ||
import PropTypes from "prop-types" | ||
|
||
import { | ||
construct, | ||
componentDidMount, | ||
componentDidUpdate, | ||
componentWillUnmount, | ||
} from "../../utils/MapChildHelper" | ||
|
||
import { MAP, DRAWING_MANAGER } from "../../constants" | ||
|
||
export const __jscodeshiftPlaceholder__ = `{ | ||
"eventMapOverrides": { | ||
"onCircleComplete": "circlecomplete", | ||
"onMarkerComplete": "markercomplete", | ||
"onOverlayComplete": "overlaycomplete", | ||
"onPolygonComplete": "polygoncomplete", | ||
"onPolylineComplete": "polylinecomplete", | ||
"onRectangleComplete": "rectanglecomplete" | ||
}, | ||
"getInstanceFromComponent": "this.state[DRAWING_MANAGER]" | ||
}` | ||
|
||
/** | ||
* @url https://developers.google.com/maps/documentation/javascript/3.exp/reference#DrawingManager | ||
*/ | ||
export class DrawingManager extends React.PureComponent { | ||
static propTypes = { | ||
__jscodeshiftPlaceholder__: null, | ||
} | ||
|
||
static contextTypes = { | ||
[MAP]: PropTypes.object, | ||
} | ||
|
||
/* | ||
* @url https://developers.google.com/maps/documentation/javascript/3.exp/reference#DrawingManager | ||
*/ | ||
constructor(props, context) { | ||
super(props, context) | ||
invariant( | ||
google.maps.drawing, | ||
`Did you include "libraries=drawing" in the URL?` | ||
) | ||
const drawingManager = new google.maps.drawing.DrawingManager() | ||
construct(DrawingManager.propTypes, updaterMap, this.props, drawingManager) | ||
drawingManager.setMap(this.context[MAP]) | ||
this.state = { | ||
[DRAWING_MANAGER]: drawingManager, | ||
} | ||
} | ||
|
||
componentDidMount() { | ||
componentDidMount(this, this.state[DRAWING_MANAGER], eventMap) | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
componentDidUpdate( | ||
this, | ||
this.state[DRAWING_MANAGER], | ||
eventMap, | ||
updaterMap, | ||
prevProps | ||
) | ||
} | ||
|
||
componentWillUnmount() { | ||
componentWillUnmount(this) | ||
const drawingManager = this.state[DRAWING_MANAGER] | ||
if (drawingManager) { | ||
drawingManager.setMap(null) | ||
} | ||
} | ||
|
||
render() { | ||
return false | ||
} | ||
} | ||
|
||
export default DrawingManager | ||
|
||
const eventMap = {} | ||
|
||
const updaterMap = {} |