-
Notifications
You must be signed in to change notification settings - Fork 936
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(StreetViewPanorama): revamp with jscodeshift
- Loading branch information
Showing
2 changed files
with
89 additions
and
197 deletions.
There are no files selected for viewing
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,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 = {} |