Skip to content

Commit

Permalink
feat(StreetViewPanorama): revamp with jscodeshift
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchentw committed Sep 13, 2017
1 parent 772f363 commit a0e6dd4
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 197 deletions.
197 changes: 0 additions & 197 deletions src/lib/StreetViewPanorama.js

This file was deleted.

89 changes: 89 additions & 0 deletions src/macros/StreetViewPanorama.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import invariant from "invariant"
import React from "react"
import PropTypes from "prop-types"

import {
construct,
componentDidMount,
componentDidUpdate,
componentWillUnmount,
} from "../utils/MapChildHelper"

import { MAP } from "../constants"

export const __jscodeshiftPlaceholder__ = `{
"eventMapOverrides": {
"onCloseClick": "closeclick"
},
"getInstanceFromComponent": "this.context[MAP]"
}`

/**
* @url https://developers.google.com/maps/documentation/javascript/3.exp/reference#StreetViewPanorama
*/
export class StreetViewPanorama extends React.PureComponent {
static propTypes = {
__jscodeshiftPlaceholder__: null,
}

static contextTypes = {
[MAP]: PropTypes.object,
}

static childContextTypes = {
[MAP]: PropTypes.object,
}

constructor(props, context) {
super(props, context)
invariant(
!!this.context[MAP],
`Did you render <StreetViewPanorama> as a child of <GoogleMap> with withGoogleMap() HOC?`
)
construct(
StreetViewPanorama.propTypes,
updaterMap,
this.props,
this.context[MAP].getStreetView()
)
}

getChildContext() {
return {
[MAP]: this.context[MAP].getStreetView(),
}
}

componentDidMount() {
componentDidMount(this, this.context[MAP].getStreetView(), eventMap)
}

componentDidUpdate(prevProps) {
componentDidUpdate(
this,
this.context[MAP].getStreetView(),
eventMap,
updaterMap,
prevProps
)
}

componentWillUnmount() {
componentWillUnmount(this)
const streetViewPanorama = this.context[MAP].getStreetView()
if (streetViewPanorama) {
streetViewPanorama.setVisible(false)
}
}

render() {
const { children } = this.props
return <div>{children}</div>
}
}

export default StreetViewPanorama

const eventMap = {}

const updaterMap = {}

0 comments on commit a0e6dd4

Please sign in to comment.