Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed the deprected componentWillMount #1056

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions lib/components/InfoWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,6 @@ var InfoWindow = (exports.InfoWindow = (function(_React$PureComponent) {
}

;(0, _createClass3.default)(InfoWindow, [
{
key: "componentWillMount",
value: function componentWillMount() {
if (!_canUseDom2.default || this.containerElement) {
return
}
if (_react2.default.version.match(/^16/)) {
this.containerElement = document.createElement("div")
}
},
},
{
key: "componentDidMount",
value: function componentDidMount() {
Expand All @@ -127,6 +116,9 @@ var InfoWindow = (exports.InfoWindow = (function(_React$PureComponent) {
eventMap
)
if (_react2.default.version.match(/^16/)) {
if (_canUseDom2.default && !this.containerElement) {
this.containerElement = document.createElement("div")
}
this.state[_constants.INFO_WINDOW].setContent(this.containerElement)
open(
this.state[_constants.INFO_WINDOW],
Expand Down
54 changes: 25 additions & 29 deletions lib/components/addons/InfoBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,35 +107,8 @@ var InfoBox = (exports.InfoBox = (function(_React$PureComponent) {

;(0, _createClass3.default)(InfoBox, [
{
key: "componentWillMount",

/*
* @see https://developers.google.com/maps/documentation/javascript/3.exp/reference#InfoBox
*/
value: function componentWillMount() {
if (!_canUseDom2.default || this.state[_constants.INFO_BOX]) {
return
}

var _require = require(/* "google-maps-infobox" uses "google" as a global variable. Since we don't
* have "google" on the server, we can not use it in server-side rendering.
* As a result, we import "google-maps-infobox" here to prevent an error on
* a isomorphic server.
*/ "google-maps-infobox"),
GoogleMapsInfobox = _require.InfoBox

var infoBox = new GoogleMapsInfobox()
;(0, _MapChildHelper.construct)(
InfoBox.propTypes,
updaterMap,
this.props,
infoBox
)
infoBox.setMap(this.context[_constants.MAP])
this.setState(
(0, _defineProperty3.default)({}, _constants.INFO_BOX, infoBox)
)
},
key: "componentDidMount",
value: function componentDidMount() {},
},
{
key: "componentDidMount",
Expand All @@ -145,6 +118,29 @@ var InfoBox = (exports.InfoBox = (function(_React$PureComponent) {
this.state[_constants.INFO_BOX],
eventMap
)
/*
* @see https://developers.google.com/maps/documentation/javascript/3.exp/reference#InfoBox
*/
if (_canUseDom2.default && !this.state[_constants.INFO_BOX]) {
var _require = require(/* "google-maps-infobox" uses "google" as a global variable. Since we don't
* have "google" on the server, we can not use it in server-side rendering.
* As a result, we import "google-maps-infobox" here to prevent an error on
* a isomorphic server.
*/ "google-maps-infobox"),
GoogleMapsInfobox = _require.InfoBox

var infoBox = new GoogleMapsInfobox()
;(0, _MapChildHelper.construct)(
InfoBox.propTypes,
updaterMap,
this.props,
infoBox
)
infoBox.setMap(this.context[_constants.MAP])
this.setState(
(0, _defineProperty3.default)({}, _constants.INFO_BOX, infoBox)
)
}
var content = document.createElement("div")
_reactDom2.default.unstable_renderSubtreeIntoContainer(
this,
Expand Down
29 changes: 11 additions & 18 deletions lib/components/places/SearchBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,27 +108,20 @@ var SearchBox = (exports.SearchBox = (function(_React$PureComponent) {
}

;(0, _createClass3.default)(SearchBox, [
{
key: "componentWillMount",
value: function componentWillMount() {
if (!_canUseDom2.default || this.containerElement) {
return
}
;(0, _invariant2.default)(
google.maps.places,
'Did you include "libraries=places" in the URL?'
)
this.containerElement = document.createElement("div")
this.handleRenderChildToContainerElement()
if (_react2.default.version.match(/^16/)) {
return
}
this.handleInitializeSearchBox()
},
},
{
key: "componentDidMount",
value: function componentDidMount() {
if (_canUseDom2.default && !this.containerElement) {
;(0, _invariant2.default)(
google.maps.places,
'Did you include "libraries=places" in the URL?'
)
this.containerElement = document.createElement("div")
this.handleRenderChildToContainerElement()
if (!_react2.default.version.match(/^16/)) {
this.handleInitializeSearchBox()
}
}
var searchBox = this.state[_constants.SEARCH_BOX]
if (_react2.default.version.match(/^16/)) {
searchBox = this.handleInitializeSearchBox()
Expand Down
4 changes: 2 additions & 2 deletions lib/withGoogleMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ function withGoogleMap(BaseComponent) {
},
},
{
key: "componentWillMount",
value: function componentWillMount() {
key: "componentDidMount",
value: function componentDidMount() {
var _props = this.props,
containerElement = _props.containerElement,
mapElement = _props.mapElement
Expand Down
11 changes: 2 additions & 9 deletions lib/withScriptjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ function withScriptjs(BaseComponent) {
},
},
{
key: "componentWillMount",
value: function componentWillMount() {
key: "componentDidMount",
value: function componentDidMount() {
var _props = this.props,
loadingElement = _props.loadingElement,
googleMapURL = _props.googleMapURL
Expand All @@ -129,11 +129,6 @@ function withScriptjs(BaseComponent) {
!!loadingElement && !!googleMapURL,
"Required props loadingElement or googleMapURL is missing. You need to provide both of them."
)
},
},
{
key: "componentDidMount",
value: function componentDidMount() {
var loadingState = this.state.loadingState

if (loadingState !== LOADING_STATE_NONE || !_canUseDom2.default) {
Expand All @@ -145,8 +140,6 @@ function withScriptjs(BaseComponent) {
// Don't load scriptjs as a dependency since we do not want this module be used on server side.
// eslint-disable-next-line global-require
var scriptjs = require("scriptjs")
var googleMapURL = this.props.googleMapURL

scriptjs(googleMapURL, this.handleLoaded)
},
},
Expand Down
12 changes: 3 additions & 9 deletions src/components/InfoWindow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,12 @@ export class InfoWindow extends React.PureComponent {
}
}

componentWillMount() {
if (!canUseDOM || this.containerElement) {
return
}
if (React.version.match(/^16/)) {
this.containerElement = document.createElement(`div`)
}
}

componentDidMount() {
componentDidMount(this, this.state[INFO_WINDOW], eventMap)
if (React.version.match(/^16/)) {
if (canUseDOM && !this.containerElement) {
this.containerElement = document.createElement(`div`)
}
this.state[INFO_WINDOW].setContent(this.containerElement)
open(this.state[INFO_WINDOW], this.context[ANCHOR])
return
Expand Down
42 changes: 22 additions & 20 deletions src/components/addons/InfoBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,30 +95,32 @@ export class InfoBox extends React.PureComponent {
[INFO_BOX]: null,
}

/*
* @see https://developers.google.com/maps/documentation/javascript/3.exp/reference#InfoBox
*/
componentWillMount() {
if (!canUseDOM || this.state[INFO_BOX]) {
return
}
const {
InfoBox: GoogleMapsInfobox,
} = require(/* "google-maps-infobox" uses "google" as a global variable. Since we don't
* have "google" on the server, we can not use it in server-side rendering.
* As a result, we import "google-maps-infobox" here to prevent an error on
* a isomorphic server.
*/ `google-maps-infobox`)
const infoBox = new GoogleMapsInfobox()
construct(InfoBox.propTypes, updaterMap, this.props, infoBox)
infoBox.setMap(this.context[MAP])
this.setState({
[INFO_BOX]: infoBox,
})

componentDidMount() {


}

componentDidMount() {
componentDidMount(this, this.state[INFO_BOX], eventMap)
/*
* @see https://developers.google.com/maps/documentation/javascript/3.exp/reference#InfoBox
*/
if (canUseDOM && !this.state[INFO_BOX]) {
const {
InfoBox: GoogleMapsInfobox,
} = require(/* "google-maps-infobox" uses "google" as a global variable. Since we don't
* have "google" on the server, we can not use it in server-side rendering.
* As a result, we import "google-maps-infobox" here to prevent an error on
* a isomorphic server.
*/ `google-maps-infobox`)
const infoBox = new GoogleMapsInfobox()
construct(InfoBox.propTypes, updaterMap, this.props, infoBox)
infoBox.setMap(this.context[MAP])
this.setState({
[INFO_BOX]: infoBox,
})
}
const content = document.createElement(`div`)
ReactDOM.unstable_renderSubtreeIntoContainer(
this,
Expand Down
2 changes: 1 addition & 1 deletion src/components/addons/MarkerClusterer.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const MapWithAMarkerClusterer = compose(
);

class DemoApp extends React.PureComponent {
componentWillMount() {
constructor() {
this.setState({ markers: [] })
}

Expand Down
27 changes: 11 additions & 16 deletions src/components/places/SearchBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,18 @@ export class SearchBox extends React.PureComponent {
[SEARCH_BOX]: null,
}

componentWillMount() {
if (!canUseDOM || this.containerElement) {
return
}
invariant(
google.maps.places,
`Did you include "libraries=places" in the URL?`
)
this.containerElement = document.createElement(`div`)
this.handleRenderChildToContainerElement()
if (React.version.match(/^16/)) {
return
}
this.handleInitializeSearchBox()
}

componentDidMount() {
if (canUseDOM && !this.containerElement) {
invariant(
google.maps.places,
`Did you include "libraries=places" in the URL?`
)
this.containerElement = document.createElement(`div`)
this.handleRenderChildToContainerElement()
if (!React.version.match(/^16/)) {
this.handleInitializeSearchBox()
}
}
let searchBox = this.state[SEARCH_BOX]
if (React.version.match(/^16/)) {
searchBox = this.handleInitializeSearchBox()
Expand Down
12 changes: 3 additions & 9 deletions src/macros/InfoWindow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,12 @@ export class InfoWindow extends React.PureComponent {
}
}

componentWillMount() {
if (!canUseDOM || this.containerElement) {
return
}
if (React.version.match(/^16/)) {
this.containerElement = document.createElement(`div`)
}
}

componentDidMount() {
componentDidMount(this, this.state[INFO_WINDOW], eventMap)
if (React.version.match(/^16/)) {
if (canUseDOM && !this.containerElement) {
this.containerElement = document.createElement(`div`)
}
this.state[INFO_WINDOW].setContent(this.containerElement)
open(this.state[INFO_WINDOW], this.context[ANCHOR])
return
Expand Down
24 changes: 8 additions & 16 deletions src/macros/places/SearchBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,15 @@ export class SearchBox extends React.PureComponent {
[SEARCH_BOX]: null,
}

componentWillMount() {
if (!canUseDOM || this.containerElement) {
return
}
invariant(
google.maps.places,
`Did you include "libraries=places" in the URL?`
)
this.containerElement = document.createElement(`div`)
this.handleRenderChildToContainerElement()
if (React.version.match(/^16/)) {
return
}
this.handleInitializeSearchBox()
}

componentDidMount() {
if (canUseDOM && !this.containerElement) {
invariant(
google.maps.places,
`Did you include "libraries=places" in the URL?`
)
this.containerElement = document.createElement(`div`)
this.handleRenderChildToContainerElement()
}
let searchBox = this.state[SEARCH_BOX]
if (React.version.match(/^16/)) {
searchBox = this.handleInitializeSearchBox()
Expand Down
2 changes: 1 addition & 1 deletion src/withGoogleMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function withGoogleMap(BaseComponent) {
}
}

componentWillMount() {
componentDidMount() {
const { containerElement, mapElement } = this.props
invariant(
!!containerElement && !!mapElement,
Expand Down
6 changes: 1 addition & 5 deletions src/withScriptjs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,12 @@ export function withScriptjs(BaseComponent) {
})
}

componentWillMount() {
componentDidMount() {
const { loadingElement, googleMapURL } = this.props
invariant(
!!loadingElement && !!googleMapURL,
`Required props loadingElement or googleMapURL is missing. You need to provide both of them.`
)
}

componentDidMount() {
const { loadingState } = this.state
if (loadingState !== LOADING_STATE_NONE || !canUseDOM) {
return
Expand All @@ -56,7 +53,6 @@ export function withScriptjs(BaseComponent) {
// Don't load scriptjs as a dependency since we do not want this module be used on server side.
// eslint-disable-next-line global-require
const scriptjs = require(`scriptjs`)
const { googleMapURL } = this.props
scriptjs(googleMapURL, this.handleLoaded)
}

Expand Down