@@ -11,27 +11,27 @@ class Reloader extends React.Component {
11
11
this . state = {
12
12
hash : null ,
13
13
interval,
14
- disabled : false
14
+ disabled : false ,
15
+ intervalId : null
15
16
}
16
17
} else {
17
18
this . state = {
18
19
disabled : true
19
20
}
20
21
}
21
- this . _intervalId = null ;
22
22
}
23
23
24
24
componentDidUpdate ( ) {
25
- const { reloadHash , dispatch} = this . props ;
26
- if ( reloadHash . status === 200 ) {
25
+ const { reloadRequest , dispatch} = this . props ;
26
+ if ( reloadRequest . status === 200 ) {
27
27
if ( this . state . hash === null ) {
28
- this . setState ( { hash : reloadHash . content . reloadHash } ) ;
28
+ this . setState ( { hash : reloadRequest . content . reloadHash } ) ;
29
29
return ;
30
30
}
31
- if ( reloadHash . content . reloadHash !== this . state . hash ) {
31
+ if ( reloadRequest . content . reloadHash !== this . state . hash ) {
32
32
// eslint-disable-next-line no-undef
33
33
window . clearInterval ( this . _intervalId ) ;
34
- if ( reloadHash . content . hard ) {
34
+ if ( reloadRequest . content . hard ) {
35
35
// Assets file have changed, need to reload them.
36
36
// eslint-disable-next-line no-undef
37
37
window . top . location . reload ( ) ;
@@ -46,17 +46,18 @@ class Reloader extends React.Component {
46
46
componentDidMount ( ) {
47
47
const { dispatch } = this . props ;
48
48
const { disabled, interval } = this . state ;
49
- if ( ! disabled && ! this . _intervalId ) {
50
- this . _intervalId = setInterval ( ( ) => {
49
+ if ( ! disabled && ! this . state . intervalId ) {
50
+ const intervalId = setInterval ( ( ) => {
51
51
dispatch ( getReloadHash ( ) ) ;
52
52
} , interval ) ;
53
+ this . setState ( { intervalId} )
53
54
}
54
55
}
55
56
56
57
componentWillUnmount ( ) {
57
- if ( ! this . state . disabled ) {
58
+ if ( ! this . state . disabled && this . state . intervalId ) {
58
59
// eslint-disable-next-line no-undef
59
- window . clearInterval ( this . _intervalId ) ;
60
+ window . clearInterval ( this . state . intervalId ) ;
60
61
}
61
62
}
62
63
@@ -70,15 +71,15 @@ Reloader.defaultProps = {};
70
71
Reloader . propTypes = {
71
72
id : PropTypes . string ,
72
73
config : PropTypes . object ,
73
- reloadHash : PropTypes . object ,
74
+ reloadRequest : PropTypes . object ,
74
75
dispatch : PropTypes . func ,
75
76
interval : PropTypes . number
76
77
} ;
77
78
78
79
export default connect (
79
80
state => ( {
80
81
config : state . config ,
81
- reloadHash : state . reloadHash
82
+ reloadRequest : state . reloadRequest
82
83
} ) ,
83
84
dispatch => ( { dispatch} )
84
85
) ( Reloader ) ;
0 commit comments