mirror of
https://github.com/google-map-react/google-map-react.git
synced 2025-12-08 18:26:32 +00:00
* improvement: switched from defining API key in multiple places to one place * now generating random readings * fix: a change in heatmap positions now updates the map accordingly * docs: added comment to explain that the developer should use their own key
49 lines
1.0 KiB
JavaScript
49 lines
1.0 KiB
JavaScript
import { createElement, Component } from 'react';
|
|
|
|
const safeTimerFactory = (setFn, clearFn, propName, hocName) =>
|
|
Target => {
|
|
class SafeTimer extends Component {
|
|
constructor(props, context) {
|
|
super(props, context);
|
|
|
|
this.unsubscribers = [];
|
|
this[propName] = this[propName].bind(this);
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
this.unsubscribers.forEach(unsubscribe => unsubscribe());
|
|
|
|
this.unsubscribers = [];
|
|
}
|
|
|
|
[propName](...args) {
|
|
const id = setFn(...args);
|
|
const unsubscriber = () => clearFn(id);
|
|
|
|
this.unsubscribers.push(unsubscriber);
|
|
|
|
return unsubscriber;
|
|
}
|
|
|
|
render() {
|
|
return createElement(Target, {
|
|
...this.props,
|
|
[propName]: this[propName],
|
|
});
|
|
}
|
|
}
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
SafeTimer.displayName = `${hocName}`;
|
|
}
|
|
|
|
return SafeTimer;
|
|
};
|
|
|
|
export default safeTimerFactory(
|
|
global.setInterval,
|
|
global.clearInterval,
|
|
'setSafeInterval',
|
|
'withSafeInterval'
|
|
);
|