From 75470f2ef75a5c61538a2b004d7f7bed9a8be965 Mon Sep 17 00:00:00 2001 From: Kevin Lindsay Date: Wed, 19 Sep 2018 19:31:17 -0400 Subject: [PATCH 1/2] fix(withScriptJs): fixed a bug where withScriptJs doesn't update when the googleMapURL changes --- src/withScriptjs.jsx | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/withScriptjs.jsx b/src/withScriptjs.jsx index 66f25cba..a0f966f4 100644 --- a/src/withScriptjs.jsx +++ b/src/withScriptjs.jsx @@ -26,8 +26,19 @@ export function withScriptjs(BaseComponent) { isUnmounted = false + handleLoading = _.bind(this.handleLoading, this) handleLoaded = _.bind(this.handleLoaded, this) + handleLoading(googleMapURL) { + this.setState({ + loadingState: LOADING_STATE_BEGIN, + }) + // 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`) + scriptjs(googleMapURL, this.handleLoaded) + } + handleLoaded() { if (this.isUnmounted) { return @@ -50,14 +61,18 @@ export function withScriptjs(BaseComponent) { if (loadingState !== LOADING_STATE_NONE || !canUseDOM) { return } - this.setState({ - loadingState: LOADING_STATE_BEGIN, - }) - // 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) + this.handleLoading(googleMapURL) + } + + componentDidUpdate(prevProps) { + const { googleMapURL: prevGoogleMapURL } = prevProps + const { googleMapURL } = this.props + + if (prevGoogleMapURL !== googleMapURL) { + this.handleLoading(googleMapURL) + } } componentWillUnmount() { From 6e3e91927d34a120cbbc353dcb5f7054147a226e Mon Sep 17 00:00:00 2001 From: Kevin Lindsay Date: Wed, 19 Sep 2018 19:40:16 -0400 Subject: [PATCH 2/2] running build for myself because --- lib/components/GroundOverlay.js | 6 ++++-- lib/withScriptjs.js | 33 ++++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/lib/components/GroundOverlay.js b/lib/components/GroundOverlay.js index 662b20ea..34a0d39c 100644 --- a/lib/components/GroundOverlay.js +++ b/lib/components/GroundOverlay.js @@ -186,11 +186,13 @@ GroundOverlay.propTypes = { /** * @type string */ - defaultUrl: _propTypes2.default.string /* v10.0.0 .isRequired */ /** + defaultUrl: _propTypes2.default.string /* v10.0.0 .isRequired */ + /** * @see https://developers.google.com/maps/documentation/javascript/reference#GroundOverlay */, - defaultBounds: _propTypes2.default.object /* v10.0.0 .isRequired */ /** + defaultBounds: _propTypes2.default.object /* v10.0.0 .isRequired */ + /** * @type string * @deprecated use `defaultUrl` instead. It will be removed in v10.0.0 */, diff --git a/lib/withScriptjs.js b/lib/withScriptjs.js index 21084d0b..ce2f4696 100644 --- a/lib/withScriptjs.js +++ b/lib/withScriptjs.js @@ -100,6 +100,7 @@ function withScriptjs(BaseComponent) { loadingState: LOADING_STATE_NONE, }), (_this.isUnmounted = false), + (_this.handleLoading = (0, _bind3.default)(_this.handleLoading, _this)), (_this.handleLoaded = (0, _bind3.default)(_this.handleLoaded, _this)), _temp)), (0, _possibleConstructorReturn3.default)(_this, _ret) @@ -107,6 +108,18 @@ function withScriptjs(BaseComponent) { } ;(0, _createClass3.default)(Container, [ + { + key: "handleLoading", + value: function handleLoading(googleMapURL) { + this.setState({ + loadingState: LOADING_STATE_BEGIN, + }) + // 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") + scriptjs(googleMapURL, this.handleLoaded) + }, + }, { key: "handleLoaded", value: function handleLoaded() { @@ -139,15 +152,21 @@ function withScriptjs(BaseComponent) { if (loadingState !== LOADING_STATE_NONE || !_canUseDom2.default) { return } - this.setState({ - loadingState: LOADING_STATE_BEGIN, - }) - // 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) + this.handleLoading(googleMapURL) + }, + }, + { + key: "componentDidUpdate", + value: function componentDidUpdate(prevProps) { + var prevGoogleMapURL = prevProps.googleMapURL + var googleMapURL = this.props.googleMapURL + + if (prevGoogleMapURL !== googleMapURL) { + this.handleLoading(googleMapURL) + } }, }, {