Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
Rename reloadHash store to reloadRequests, add intervalId as state.
Browse files Browse the repository at this point in the history
  • Loading branch information
T4rk1n committed Sep 13, 2018
1 parent 1a8fd9c commit 9c9c797
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
27 changes: 14 additions & 13 deletions src/components/core/Reloader.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ class Reloader extends React.Component {
this.state = {
hash: null,
interval,
disabled: false
disabled: false,
intervalId: null
}
} else {
this.state = {
disabled: true
}
}
this._intervalId = null;
}

componentDidUpdate() {
const {reloadHash, dispatch} = this.props;
if (reloadHash.status === 200) {
const {reloadRequest, dispatch} = this.props;
if (reloadRequest.status === 200) {
if (this.state.hash === null) {
this.setState({hash: reloadHash.content.reloadHash});
this.setState({hash: reloadRequest.content.reloadHash});
return;
}
if (reloadHash.content.reloadHash !== this.state.hash) {
if (reloadRequest.content.reloadHash !== this.state.hash) {
// eslint-disable-next-line no-undef
window.clearInterval(this._intervalId);
if (reloadHash.content.hard) {
if (reloadRequest.content.hard) {
// Assets file have changed, need to reload them.
// eslint-disable-next-line no-undef
window.top.location.reload();
Expand All @@ -46,17 +46,18 @@ class Reloader extends React.Component {
componentDidMount() {
const { dispatch } = this.props;
const { disabled, interval } = this.state;
if (!disabled && !this._intervalId) {
this._intervalId = setInterval(() => {
if (!disabled && !this.state.intervalId) {
const intervalId = setInterval(() => {
dispatch(getReloadHash());
}, interval);
this.setState({intervalId})
}
}

componentWillUnmount() {
if (!this.state.disabled) {
if (!this.state.disabled && this.state.intervalId) {
// eslint-disable-next-line no-undef
window.clearInterval(this._intervalId);
window.clearInterval(this.state.intervalId);
}
}

Expand All @@ -70,15 +71,15 @@ Reloader.defaultProps = {};
Reloader.propTypes = {
id: PropTypes.string,
config: PropTypes.object,
reloadHash: PropTypes.object,
reloadRequest: PropTypes.object,
dispatch: PropTypes.func,
interval: PropTypes.number
};

export default connect(
state => ({
config: state.config,
reloadHash: state.reloadHash
reloadRequest: state.reloadRequest
}),
dispatch => ({dispatch})
)(Reloader);
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const reducer = combineReducers({
dependenciesRequest: API.dependenciesRequest,
layoutRequest: API.layoutRequest,
loginRequest: API.loginRequest,
reloadHash: API.reloadRequest,
reloadRequest: API.reloadRequest,
history
});

Expand Down

0 comments on commit 9c9c797

Please sign in to comment.