@@ -3,67 +3,66 @@ import configureStore from '../../../app/store/configureStore';
33import { ACTION , UPDATE , OPTIONS , COMMIT } from '../../../app/constants/ActionTypes' ;
44import { isAllowed } from '../options/syncOptions' ;
55
6+ window . devToolsExtension = function ( next ) {
7+ function devToolsInit ( store ) {
8+ if ( ! window . devToolsOptions ) window . devToolsOptions = { } ;
9+ let timeout = { id : null , last : 0 } ;
610
7- window . devToolsInit = function ( store ) {
8- if ( ! window . devToolsOptions ) window . devToolsOptions = { } ;
9- let timeout = { id : null , last : 0 } ;
10-
11- function doChange ( init ) {
12- const state = store . liftedStore . getState ( ) ;
13- if ( window . devToolsOptions . limit && state . currentStateIndex > window . devToolsOptions . limit ) {
14- store . liftedStore . dispatch ( { type : COMMIT , timestamp : Date . now ( ) } ) ;
15- return ;
11+ function doChange ( init ) {
12+ const state = store . liftedStore . getState ( ) ;
13+ if ( window . devToolsOptions . limit && state . currentStateIndex > window . devToolsOptions . limit ) {
14+ store . liftedStore . dispatch ( { type : COMMIT , timestamp : Date . now ( ) } ) ;
15+ return ;
16+ }
17+ window . postMessage ( {
18+ payload : typeof window . devToolsOptions . serialize === 'undefined' || window . devToolsOptions . serialize ? stringify ( state ) : state ,
19+ source : 'redux-page' ,
20+ init : init || false
21+ } , '*' ) ;
1622 }
17- window . postMessage ( {
18- payload : typeof window . devToolsOptions . serialize === 'undefined' || window . devToolsOptions . serialize ? stringify ( state ) : state ,
19- source : 'redux-page' ,
20- init : init || false
21- } , '*' ) ;
22- }
2323
24- function onChange ( init ) {
25- if ( init || ! window . devToolsOptions . timeout ) doChange ( init ) ;
26- else if ( ! timeout . last ) {
27- doChange ( ) ;
28- timeout . last = Date . now ( ) ;
29- } else {
30- const timeoutValue = ( window . devToolsOptions . timeout * 1000 - ( Date . now ( ) - timeout . last ) ) ;
31- window . clearTimeout ( timeout . id ) ;
32- if ( timeoutValue <= 0 ) {
24+ function onChange ( init ) {
25+ if ( init || ! window . devToolsOptions . timeout ) doChange ( init ) ;
26+ else if ( ! timeout . last ) {
3327 doChange ( ) ;
3428 timeout . last = Date . now ( ) ;
29+ } else {
30+ const timeoutValue = ( window . devToolsOptions . timeout * 1000 - ( Date . now ( ) - timeout . last ) ) ;
31+ window . clearTimeout ( timeout . id ) ;
32+ if ( timeoutValue <= 0 ) {
33+ doChange ( ) ;
34+ timeout . last = Date . now ( ) ;
35+ }
36+ else timeout . id = setTimeout ( doChange , timeoutValue ) ;
3537 }
36- else timeout . id = setTimeout ( doChange , timeoutValue ) ;
3738 }
38- }
3939
40- function onMessage ( event ) {
41- if ( ! event || event . source !== window ) {
42- return ;
43- }
40+ function onMessage ( event ) {
41+ if ( ! event || event . source !== window ) {
42+ return ;
43+ }
4444
45- const message = event . data ;
45+ const message = event . data ;
4646
47- if ( ! message || message . source !== 'redux-cs' ) {
48- return ;
49- }
47+ if ( ! message || message . source !== 'redux-cs' ) {
48+ return ;
49+ }
5050
51- if ( message . type === ACTION ) {
52- timeout . last = 0 ;
53- store . liftedStore . dispatch ( message . payload ) ;
54- } else if ( message . type === UPDATE ) {
55- onChange ( ) ;
56- }
51+ if ( message . type === ACTION ) {
52+ timeout . last = 0 ;
53+ store . liftedStore . dispatch ( message . payload ) ;
54+ } else if ( message . type === UPDATE ) {
55+ onChange ( ) ;
56+ }
5757
58- }
58+ }
5959
60- store . liftedStore . subscribe ( onChange ) ;
61- window . addEventListener ( 'message' , onMessage , false ) ;
60+ store . liftedStore . subscribe ( onChange ) ;
61+ window . addEventListener ( 'message' , onMessage , false ) ;
6262
63- onChange ( true ) ;
64- } ;
63+ onChange ( true ) ;
64+ }
6565
66- window . devToolsExtension = function ( next ) {
6766 if ( next ) {
6867 console . warn ( 'Please use \'window.devToolsExtension()\' instead of \'window.devToolsExtension\' as store enhancer. The latter will not be supported.' ) ;
6968 return ( reducer , initialState ) => {
0 commit comments