Skip to content

Commit d869f0a

Browse files
author
Michael Ruoss
committed
Merge remote-tracking branch 'upstream/master' into feature/accept-functions-as-input
# Conflicts: # README.md # src/GoogleApiComponent.js
2 parents 044aa37 + 30a3e07 commit d869f0a

21 files changed

+735
-399
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ export default GoogleApiWrapper(
4343
))(MapContainer)
4444
```
4545

46+
If you want to add a loading container _other than the default_ loading container, simply pass it in the HOC, like so:
47+
48+
```javascript
49+
const LoadingContainer = (props) => (
50+
<div>Fancy loading container!</div>
51+
)
52+
export default GoogleApiWrapper({
53+
apiKey: (YOUR_GOOGLE_API_KEY_GOES_HERE),
54+
LoadingContainer: LoadingContainer
55+
})(MapContainer)
56+
```
57+
4658
## Sample Usage With Lazy-loading Google API:
4759

4860
```javascript
@@ -439,6 +451,12 @@ If you prefer not to use the automatic loading option, you can also pass the `wi
439451
<Map google={window.google} />
440452
```
441453

454+
## Issues?
455+
456+
If you have some issues, please make an issue on the issues tab and try to include an example. We've had success with https://codesandbox.io
457+
458+
An example template might look like: [https://codesandbox.io/s/x3xxjr7r04](https://codesandbox.io/s/x3xxjr7r04)
459+
442460
## Contributing
443461

444462
```shell

dist/GoogleApiComponent.js

Lines changed: 148 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,154 +1,171 @@
11
(function (global, factory) {
2-
if (typeof define === "function" && define.amd) {
3-
define(['exports', 'react', 'react-dom', './lib/ScriptCache', './lib/GoogleApi'], factory);
4-
} else if (typeof exports !== "undefined") {
5-
factory(exports, require('react'), require('react-dom'), require('./lib/ScriptCache'), require('./lib/GoogleApi'));
6-
} else {
7-
var mod = {
8-
exports: {}
9-
};
10-
factory(mod.exports, global.react, global.reactDom, global.ScriptCache, global.GoogleApi);
11-
global.GoogleApiComponent = mod.exports;
12-
}
2+
if (typeof define === "function" && define.amd) {
3+
define(['exports', 'react', 'react-dom', './lib/ScriptCache', './lib/GoogleApi'], factory);
4+
} else if (typeof exports !== "undefined") {
5+
factory(exports, require('react'), require('react-dom'), require('./lib/ScriptCache'), require('./lib/GoogleApi'));
6+
} else {
7+
var mod = {
8+
exports: {}
9+
};
10+
factory(mod.exports, global.react, global.reactDom, global.ScriptCache, global.GoogleApi);
11+
global.GoogleApiComponent = mod.exports;
12+
}
1313
})(this, function (exports, _react, _reactDom, _ScriptCache, _GoogleApi) {
14-
'use strict';
14+
'use strict';
1515

16-
Object.defineProperty(exports, "__esModule", {
17-
value: true
18-
});
19-
exports.wrapper = undefined;
16+
Object.defineProperty(exports, "__esModule", {
17+
value: true
18+
});
19+
exports.wrapper = undefined;
2020

21-
var _react2 = _interopRequireDefault(_react);
21+
var _react2 = _interopRequireDefault(_react);
2222

23-
var _reactDom2 = _interopRequireDefault(_reactDom);
23+
var _reactDom2 = _interopRequireDefault(_reactDom);
2424

25-
var _GoogleApi2 = _interopRequireDefault(_GoogleApi);
25+
var _GoogleApi2 = _interopRequireDefault(_GoogleApi);
2626

27-
function _interopRequireDefault(obj) {
28-
return obj && obj.__esModule ? obj : {
29-
default: obj
30-
};
31-
}
27+
function _interopRequireDefault(obj) {
28+
return obj && obj.__esModule ? obj : {
29+
default: obj
30+
};
31+
}
3232

33-
function _classCallCheck(instance, Constructor) {
34-
if (!(instance instanceof Constructor)) {
35-
throw new TypeError("Cannot call a class as a function");
36-
}
33+
function _classCallCheck(instance, Constructor) {
34+
if (!(instance instanceof Constructor)) {
35+
throw new TypeError("Cannot call a class as a function");
36+
}
37+
}
38+
39+
var _createClass = function () {
40+
function defineProperties(target, props) {
41+
for (var i = 0; i < props.length; i++) {
42+
var descriptor = props[i];
43+
descriptor.enumerable = descriptor.enumerable || false;
44+
descriptor.configurable = true;
45+
if ("value" in descriptor) descriptor.writable = true;
46+
Object.defineProperty(target, descriptor.key, descriptor);
47+
}
3748
}
3849

39-
var _createClass = function () {
40-
function defineProperties(target, props) {
41-
for (var i = 0; i < props.length; i++) {
42-
var descriptor = props[i];
43-
descriptor.enumerable = descriptor.enumerable || false;
44-
descriptor.configurable = true;
45-
if ("value" in descriptor) descriptor.writable = true;
46-
Object.defineProperty(target, descriptor.key, descriptor);
47-
}
48-
}
50+
return function (Constructor, protoProps, staticProps) {
51+
if (protoProps) defineProperties(Constructor.prototype, protoProps);
52+
if (staticProps) defineProperties(Constructor, staticProps);
53+
return Constructor;
54+
};
55+
}();
4956

50-
return function (Constructor, protoProps, staticProps) {
51-
if (protoProps) defineProperties(Constructor.prototype, protoProps);
52-
if (staticProps) defineProperties(Constructor, staticProps);
53-
return Constructor;
54-
};
55-
}();
57+
function _possibleConstructorReturn(self, call) {
58+
if (!self) {
59+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
60+
}
5661

57-
function _possibleConstructorReturn(self, call) {
58-
if (!self) {
59-
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
60-
}
62+
return call && (typeof call === "object" || typeof call === "function") ? call : self;
63+
}
6164

62-
return call && (typeof call === "object" || typeof call === "function") ? call : self;
65+
function _inherits(subClass, superClass) {
66+
if (typeof superClass !== "function" && superClass !== null) {
67+
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
6368
}
6469

65-
function _inherits(subClass, superClass) {
66-
if (typeof superClass !== "function" && superClass !== null) {
67-
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
70+
subClass.prototype = Object.create(superClass && superClass.prototype, {
71+
constructor: {
72+
value: subClass,
73+
enumerable: false,
74+
writable: true,
75+
configurable: true
76+
}
77+
});
78+
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
79+
}
80+
81+
var defaultMapConfig = {};
82+
var defaultCreateCache = function defaultCreateCache(options) {
83+
options = options || {};
84+
var apiKey = options.apiKey;
85+
var libraries = options.libraries || ['places'];
86+
var version = options.version || '3';
87+
var language = options.language || 'en';
88+
var url = options.url;
89+
90+
return (0, _ScriptCache.ScriptCache)({
91+
google: (0, _GoogleApi2.default)({
92+
apiKey: apiKey,
93+
language: language,
94+
libraries: libraries,
95+
version: version,
96+
url: url
97+
})
98+
});
99+
};
100+
101+
var DefaultLoadingContainer = function DefaultLoadingContainer(props) {
102+
return _react2.default.createElement(
103+
'div',
104+
null,
105+
'Loading...'
106+
);
107+
};
108+
109+
var wrapper = exports.wrapper = function wrapper(options) {
110+
return function (WrappedComponent) {
111+
var createCache = options.createCache || defaultCreateCache;
112+
113+
var Wrapper = function (_React$Component) {
114+
_inherits(Wrapper, _React$Component);
115+
116+
function Wrapper(props, context) {
117+
_classCallCheck(this, Wrapper);
118+
119+
var _this = _possibleConstructorReturn(this, (Wrapper.__proto__ || Object.getPrototypeOf(Wrapper)).call(this, props, context));
120+
121+
_this.scriptCache = createCache(options);
122+
_this.scriptCache.google.onLoad(_this.onLoad.bind(_this));
123+
_this.LoadingContainer = options.LoadingContainer || DefaultLoadingContainer;
124+
125+
_this.state = {
126+
loaded: false,
127+
map: null,
128+
google: null
129+
};
130+
return _this;
68131
}
69132

70-
subClass.prototype = Object.create(superClass && superClass.prototype, {
71-
constructor: {
72-
value: subClass,
73-
enumerable: false,
74-
writable: true,
75-
configurable: true
133+
_createClass(Wrapper, [{
134+
key: 'onLoad',
135+
value: function onLoad(err, tag) {
136+
this._gapi = window.google;
137+
138+
this.setState({ loaded: true, google: this._gapi });
139+
}
140+
}, {
141+
key: 'render',
142+
value: function render() {
143+
var LoadingContainer = this.LoadingContainer;
144+
145+
if (!this.state.loaded) {
146+
return _react2.default.createElement(LoadingContainer, null);
76147
}
77-
});
78-
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
79-
}
80148

81-
var defaultMapConfig = {};
82-
var defaultCreateCache = function defaultCreateCache(options) {
83-
options = options || {};
84-
var apiKey = options.apiKey;
85-
var libraries = options.libraries || ['places'];
86-
var version = options.version || '3.29';
87-
var language = options.language || 'en';
88-
89-
return (0, _ScriptCache.ScriptCache)({
90-
google: (0, _GoogleApi2.default)({
91-
apiKey: apiKey,
92-
language: language,
93-
libraries: libraries,
94-
version: version
95-
})
96-
});
97-
};
149+
var props = Object.assign({}, this.props, {
150+
loaded: this.state.loaded,
151+
google: window.google
152+
});
153+
154+
return _react2.default.createElement(
155+
'div',
156+
null,
157+
_react2.default.createElement(WrappedComponent, props),
158+
_react2.default.createElement('div', { ref: 'map' })
159+
);
160+
}
161+
}]);
162+
163+
return Wrapper;
164+
}(_react2.default.Component);
98165

99-
var wrapper = exports.wrapper = function wrapper(options) {
100-
return function (WrappedComponent) {
101-
var createCache = options.createCache || defaultCreateCache;
102-
103-
var Wrapper = function (_React$Component) {
104-
_inherits(Wrapper, _React$Component);
105-
106-
function Wrapper(props, context) {
107-
_classCallCheck(this, Wrapper);
108-
109-
var _this = _possibleConstructorReturn(this, (Wrapper.__proto__ || Object.getPrototypeOf(Wrapper)).call(this, props, context));
110-
111-
_this.scriptCache = createCache(options);
112-
_this.scriptCache.google.onLoad(_this.onLoad.bind(_this));
113-
114-
_this.state = {
115-
loaded: false,
116-
map: null,
117-
google: null
118-
};
119-
return _this;
120-
}
121-
122-
_createClass(Wrapper, [{
123-
key: 'onLoad',
124-
value: function onLoad(err, tag) {
125-
this._gapi = window.google;
126-
127-
this.setState({ loaded: true, google: this._gapi });
128-
}
129-
}, {
130-
key: 'render',
131-
value: function render() {
132-
var props = Object.assign({}, this.props, {
133-
loaded: this.state.loaded,
134-
google: window.google
135-
});
136-
137-
return _react2.default.createElement(
138-
'div',
139-
null,
140-
_react2.default.createElement(WrappedComponent, props),
141-
_react2.default.createElement('div', { ref: 'map' })
142-
);
143-
}
144-
}]);
145-
146-
return Wrapper;
147-
}(_react2.default.Component);
148-
149-
return Wrapper;
150-
};
166+
return Wrapper;
151167
};
168+
};
152169

153-
exports.default = wrapper;
170+
exports.default = wrapper;
154171
});

0 commit comments

Comments
 (0)