Skip to content

Commit 5e6337f

Browse files
committed
Merge pull request #79 from evgenykochetkov/add-actionsBlacklist-actionsWhitelist-config-options
Add actionsBlacklist and actionsWhitelist config options
2 parents e9df9bd + 78908ab commit 5e6337f

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ If you do not know what [Redux DevTools](https://github.com/gaearon/redux-devtoo
8585
- state, transformedState - Redux state objects
8686
- **deserializeAction(action): transformedAction** (*function*) - optional transformation of actions deserialized from debug session (useful if actions are not plain object. Example: immutable-js action payload)
8787
- action, transformedAction - Redux action objects
88+
- **actionsBlacklist** (*array*) - actions to be hidden in DevTools. Overwrites corresponding global setting in the options page.
89+
- **actionsWhitelist** (*array*) - all other actions will be hidden in DevTools. Overwrites corresponding global setting in the options page.
8890

8991
## Examples
9092
Open these urls to test the extension:
@@ -106,7 +108,8 @@ Also you may run them from `./examples` folder (on port 4001 and 4002 by default
106108
- If something goes wrong, [open an issue](https://github.com/zalmoxisus/redux-devtools-extension/issues) or tweet me: [@mdiordiev](https://twitter.com/mdiordiev).
107109

108110
#### How to filter actions
109-
On the options page you may enable actions filtering and specify either actions to be hidden or shown in DevTools. If the latter is specified, other than those actions will be hidden.
111+
On the options page you may enable actions filtering and specify either actions to be hidden or shown in DevTools. If the latter is specified, other than those actions will be hidden.
112+
You can overwrite theese settings for an individual project using `actionsBlacklist` and `actionsWhitelist` [config options](#API).
110113
#### How to disable/enable it in production
111114
On the options page you may enable the extension to be injected in all pages or you may specify the pages urls to be injected in. Use regex values and new line as a separator.
112115
#### How to open Redux DevTools in a new window

src/browser/extension/inject/pageScript.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@ import configureStore from '../../../app/store/configureStore';
33
import { isAllowed } from '../options/syncOptions';
44
import notifyErrors from '../utils/notifyErrors';
55

6+
const actionsArrToReg = (arr) => arr ? arr.join('|') : null;
7+
68
window.devToolsExtension = function(config = {}) {
79
let store = {};
810
if (!window.devToolsOptions) window.devToolsOptions = {};
11+
12+
let localFilter;
13+
if (config.actionsBlacklist || config.actionsWhitelist) {
14+
localFilter = {
15+
whitelist: actionsArrToReg(config.actionsWhitelist),
16+
blacklist: actionsArrToReg(config.actionsBlacklist)
17+
};
18+
}
19+
920
let shouldSerialize = false;
1021
let lastAction;
1122
let errorOccurred = false;
@@ -75,18 +86,19 @@ window.devToolsExtension = function(config = {}) {
7586
}
7687

7788
function isFiltered(action) {
78-
if (!window.devToolsOptions.filter) return false;
79-
const { whitelist, blacklist } = window.devToolsOptions;
89+
if (!localFilter && !window.devToolsOptions.filter) return false;
90+
const { whitelist, blacklist } = localFilter || window.devToolsOptions;
8091
return (
8192
whitelist && !action.type.match(whitelist) ||
8293
blacklist && action.type.match(blacklist)
8394
);
8495
}
8596

8697
function addFilter(state) {
87-
if (window.devToolsOptions.filter) {
88-
if (window.devToolsOptions.whitelist) state.whitelist = [window.devToolsOptions.whitelist];
89-
else if (window.devToolsOptions.blacklist) state.blacklist = [window.devToolsOptions.blacklist];
98+
if (localFilter || window.devToolsOptions.filter) {
99+
const { whitelist, blacklist } = localFilter || window.devToolsOptions;
100+
if (whitelist) state.whitelist = [whitelist];
101+
else if (blacklist) state.blacklist = [blacklist];
90102
}
91103
}
92104

0 commit comments

Comments
 (0)