Skip to content

Commit

Permalink
feat(drawing/DrawingManager): revamp with jscodeshift
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchentw committed Sep 13, 2017
1 parent a0e6dd4 commit 01bfb80
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 119 deletions.
8 changes: 8 additions & 0 deletions src/drawing/DrawingManager.js
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"
110 changes: 0 additions & 110 deletions src/lib/drawing/DrawingManager.js

This file was deleted.

9 changes: 0 additions & 9 deletions src/lib/drawing/drawingManager.spec.js

This file was deleted.

87 changes: 87 additions & 0 deletions src/macros/drawing/DrawingManager.jsx
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 = {}

0 comments on commit 01bfb80

Please sign in to comment.