Skip to content

Commit 499cdd4

Browse files
committed
Add actionsFilter and statesFilter props
1 parent 8b0f353 commit 499cdd4

File tree

3 files changed

+50
-9
lines changed

3 files changed

+50
-9
lines changed

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,15 @@ import FilterMonitor from 'redux-devtools-filter-actions';
2222
import LogMonitor from 'redux-devtools-log-monitor';
2323

2424
export default createDevTools(
25-
<FilterMonitor blacklist={['ACTION1', 'ACTION2']}>
25+
<FilterMonitor
26+
blacklist={['ACTION1', 'ACTION2']}
27+
actionsFilter={(action) => (
28+
action.type === 'FILE_DOWNLOAD_SUCCESS' && action.data ?
29+
{ ...action, data: '<<LONG_BLOB>>' } : action
30+
)
31+
}
32+
statesFilter={(state) => state.data ? { ...state, data: '<<LONG_BLOB>>' } : state}
33+
>
2634
<LogMonitor />
2735
</FilterMonitor>
2836
);
@@ -38,6 +46,8 @@ Name | Description
3846
------------- | -------------
3947
`blacklist` | An array of actions (regex as string) to be hidden in the child monitor.
4048
`whitelist` | An array of actions (regex as string) to be shown. If specified, other than those actions will be hidden (the 'blacklist' parameter will be ignored).
49+
`actionsFilter` | Function which takes `action` object and id number as arguments, and should return `action` object back. See the example above.
50+
`statesFilter` | Function which takes `state` object and index as arguments, and should return `state` object back. See the example above.
4151

4252
### License
4353

package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"version": "1.1.2",
44
"description": "A composable monitor for Redux DevTools with the ability to filter actions.",
55
"main": "lib/index.js",
6-
"files": ["lib"],
6+
"files": [
7+
"lib"
8+
],
79
"scripts": {
810
"clean": "rimraf lib",
911
"build": "babel src --out-dir lib",
@@ -51,5 +53,8 @@
5153
"peerDependencies": {
5254
"react": "^0.14.0 || ^15.0.0-0",
5355
"redux-devtools": "^3.0.0"
56+
},
57+
"dependencies": {
58+
"lodash": "^4.12.0"
5459
}
5560
}

src/FilterMonitor.js

+33-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { cloneElement, Component, PropTypes } from 'react';
2+
import mapValues from 'lodash/mapValues';
23
import reducer from './reducers';
34

45
export default class FilterMonitor extends Component {
@@ -20,30 +21,55 @@ export default class FilterMonitor extends Component {
2021

2122
render() {
2223
let {
23-
whitelist, blacklist, monitorState, children,
24-
stagedActionIds, computedStates,
24+
whitelist, blacklist, actionsFilter, statesFilter,
25+
monitorState, children, actionsById, stagedActionIds, computedStates,
2526
...rest
2627
} = this.props;
27-
const filteredStagedActionIds = [];
28-
const filteredComputedStates = [];
28+
let filteredStagedActionIds = [];
29+
let filteredComputedStates = [];
30+
let filteredActionsById = {};
2931

3032
if (whitelist || blacklist) {
3133
stagedActionIds.forEach((id, idx) => {
32-
if (this.isNotFiltered(rest.actionsById[id].action.type)) {
34+
if (this.isNotFiltered(actionsById[id].action.type)) {
3335
filteredStagedActionIds.push(id);
34-
filteredComputedStates.push(computedStates[idx]);
36+
filteredComputedStates.push(
37+
statesFilter ?
38+
{ ...computedStates[idx], state: statesFilter(computedStates[idx].state, idx) } :
39+
computedStates[idx]
40+
);
41+
filteredActionsById[id] = (
42+
actionsFilter ?
43+
{ ...actionsById[id], action: actionsFilter(actionsById[id].action, id) } :
44+
actionsById[id]
45+
);
3546
}
3647
});
3748

3849
rest = {
3950
...rest,
51+
actionsById: filteredActionsById,
4052
stagedActionIds: filteredStagedActionIds,
4153
computedStates: filteredComputedStates
4254
};
4355
} else {
56+
if (actionsFilter) {
57+
filteredActionsById = mapValues(actionsById, (action, id) => (
58+
{ ...action, action: actionsFilter(action.action, id) }
59+
));
60+
} else filteredActionsById = actionsById;
61+
62+
if (statesFilter) {
63+
filteredComputedStates = computedStates.map((state, idx) => (
64+
{ ...state, state: statesFilter(state.state, idx) }
65+
));
66+
} else filteredComputedStates = computedStates;
67+
4468
rest = {
4569
...rest,
46-
stagedActionIds, computedStates
70+
stagedActionIds,
71+
actionsById: filteredActionsById,
72+
computedStates: filteredComputedStates
4773
};
4874
}
4975

0 commit comments

Comments
 (0)