Skip to content

Commit c2c98ab

Browse files
committed
feat(Circle): revamp with jscodeshift
1 parent f433a50 commit c2c98ab

File tree

2 files changed

+85
-144
lines changed

2 files changed

+85
-144
lines changed

src/lib/Circle.js

Lines changed: 0 additions & 144 deletions
This file was deleted.

src/macros/Circle.jsx

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/* global google */
2+
import React from "react"
3+
import PropTypes from "prop-types"
4+
5+
import {
6+
construct,
7+
componentDidMount,
8+
componentDidUpdate,
9+
componentWillUnmount,
10+
} from "../utils/MapChildHelper"
11+
12+
import { MAP, CIRCLE } from "../constants"
13+
14+
export const __jscodeshiftPlaceholder__ = `{
15+
"eventMapOverrides": {
16+
"onDblClick": "dblclick",
17+
"onDragEnd": "dragend",
18+
"onDragStart": "dragstart",
19+
"onMouseDown": "mousedown",
20+
"onMouseMove": "mousemove",
21+
"onMouseOut": "mouseout",
22+
"onMouseOver": "mouseover",
23+
"onMouseUp": "mouseup",
24+
"onRightClick": "rightclick"
25+
},
26+
"getInstanceFromComponent": "this.state[CIRCLE]"
27+
}`
28+
29+
/**
30+
* @url https://developers.google.com/maps/documentation/javascript/3.exp/reference#Circle
31+
*/
32+
export class Circle extends React.PureComponent {
33+
static propTypes = {
34+
__jscodeshiftPlaceholder__: null,
35+
}
36+
37+
static contextTypes = {
38+
[MAP]: PropTypes.object,
39+
}
40+
41+
/*
42+
* @url https://developers.google.com/maps/documentation/javascript/3.exp/reference#Circle
43+
*/
44+
constructor(props, context) {
45+
super(props, context)
46+
const circle = new google.maps.Circle()
47+
construct(Circle.propTypes, updaterMap, this.props, circle)
48+
circle.setMap(this.context[MAP])
49+
this.state = {
50+
[CIRCLE]: circle,
51+
}
52+
}
53+
54+
componentDidMount() {
55+
componentDidMount(this, this.state[CIRCLE], eventMap)
56+
}
57+
58+
componentDidUpdate(prevProps) {
59+
componentDidUpdate(
60+
this,
61+
this.state[CIRCLE],
62+
eventMap,
63+
updaterMap,
64+
prevProps
65+
)
66+
}
67+
68+
componentWillUnmount() {
69+
componentWillUnmount(this)
70+
const circle = this.state[CIRCLE]
71+
if (circle) {
72+
circle.setMap(null)
73+
}
74+
}
75+
76+
render() {
77+
return false
78+
}
79+
}
80+
81+
export default Circle
82+
83+
const eventMap = {}
84+
85+
const updaterMap = {}

0 commit comments

Comments
 (0)