@@ -3,6 +3,7 @@ import jsan from 'jsan';
33import logMonitorReducer from 'redux-devtools-log-monitor/lib/reducers' ;
44import configureStore from '../../../app/store/configureStore' ;
55import { isAllowed } from '../options/syncOptions' ;
6+ import { getLocalFilter , isFiltered , filterState } from '../utils/filters' ;
67import notifyErrors from '../utils/notifyErrors' ;
78
89const monitorActions = [
@@ -11,18 +12,11 @@ const monitorActions = [
1112] ;
1213
1314window . devToolsExtension = function ( config = { } ) {
14- let store ;
15- let liftedStore ;
1615 if ( ! window . devToolsOptions ) window . devToolsOptions = { } ;
1716
18- let localFilter ;
19- if ( config . actionsBlacklist || config . actionsWhitelist ) {
20- localFilter = {
21- whitelist : config . actionsWhitelist && config . actionsWhitelist . join ( '|' ) ,
22- blacklist : config . actionsBlacklist && config . actionsBlacklist . join ( '|' )
23- } ;
24- }
25-
17+ let store ;
18+ let liftedStore ;
19+ let localFilter = getLocalFilter ( config ) ;
2620 let shouldSerialize = false ;
2721 let lastAction ;
2822 let errorOccurred = false ;
@@ -41,20 +35,24 @@ window.devToolsExtension = function(config = {}) {
4135
4236 function relaySerialized ( message ) {
4337 if ( message . payload ) message . payload = stringify ( message . payload ) ;
44- if ( message . action !== '' ) message . action = stringify ( message . action ) ;
38+ if ( message . action ) message . action = stringify ( message . action ) ;
4539 window . postMessage ( message , '*' ) ;
4640 }
4741
4842 function relay ( type , state , action , nextActionId ) {
4943 const message = {
50- payload : type === 'STATE' && shouldFilter ( ) ? filterActions ( state ) : state ,
51- action : action || '' ,
52- nextActionId : nextActionId || '' ,
53- isExcess,
5444 type,
45+ payload : filterState ( state , type , localFilter ) ,
5546 source : 'redux-page' ,
5647 name : config . name || document . title
5748 } ;
49+
50+ if ( action ) message . action = action ;
51+ if ( type === 'ACTION' ) {
52+ message . isExcess = isExcess ;
53+ message . nextActionId = nextActionId ;
54+ }
55+
5856 if ( shouldSerialize || window . devToolsOptions . serialize ) {
5957 relaySerialized ( message ) ;
6058 } else {
@@ -118,31 +116,6 @@ window.devToolsExtension = function(config = {}) {
118116 }
119117 }
120118
121- const shouldFilter = ( ) => localFilter || window . devToolsOptions . filter ;
122- function isFiltered ( action ) {
123- if ( ! localFilter && ! window . devToolsOptions . filter ) return false ;
124- const { whitelist, blacklist } = localFilter || window . devToolsOptions ;
125- return (
126- whitelist && ! action . type . match ( whitelist ) ||
127- blacklist && action . type . match ( blacklist )
128- ) ;
129- }
130- function filterActions ( state ) {
131- const filteredStagedActionIds = [ ] ;
132- const filteredComputedStates = [ ] ;
133- state . stagedActionIds . forEach ( ( id , idx ) => {
134- if ( ! isFiltered ( state . actionsById [ id ] . action ) ) {
135- filteredStagedActionIds . push ( id ) ;
136- filteredComputedStates . push ( state . computedStates [ idx ] ) ;
137- }
138- } ) ;
139-
140- return { ...state ,
141- stagedActionIds : filteredStagedActionIds ,
142- computedStates : filteredComputedStates
143- } ;
144- }
145-
146119 function init ( ) {
147120 if ( window . devToolsExtension . __listener ) {
148121 window . removeEventListener ( 'message' , window . devToolsExtension . __listener ) ;
@@ -188,7 +161,7 @@ window.devToolsExtension = function(config = {}) {
188161 if ( action . type === '@@INIT' ) {
189162 relay ( 'INIT' , state , { timestamp : Date . now ( ) } ) ;
190163 } else if ( ! errorOccurred && monitorActions . indexOf ( lastAction ) === - 1 ) {
191- if ( lastAction === 'JUMP_TO_STATE' || shouldFilter ( ) && isFiltered ( action ) ) return ;
164+ if ( lastAction === 'JUMP_TO_STATE' || isFiltered ( action , localFilter ) ) return ;
192165 const { maxAge } = window . devToolsOptions ;
193166 relay ( 'ACTION' , state , liftedAction , nextActionId ) ;
194167 if ( ! isExcess && maxAge ) isExcess = liftedState . stagedActionIds . length >= maxAge ;
0 commit comments