Skip to content

Commit

Permalink
Filter computedStates along with stagedActionIds
Browse files Browse the repository at this point in the history
Fix #4.
  • Loading branch information
zalmoxisus committed Jan 14, 2016
1 parent d427ff4 commit baaf6a5
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/FilterMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,39 @@ export default class FilterMonitor extends Component {
blacklist: PropTypes.array
};

isFiltered(action) {
return (
this.props.whitelist && this.props.whitelist.indexOf(action) !== -1 ||
this.props.blacklist && this.props.blacklist.indexOf(action) === -1
);
}

render() {
const { whitelist, blacklist, monitorState, children, ...rest } = this.props;
const {
whitelist, blacklist, monitorState, children,
stagedActionIds, computedStates,
...rest
} = this.props;
const filteredStagedActionIds = [];
const filteredComputedStates = [];

if (whitelist || blacklist) {
let { stagedActionIds, actionsById } = rest;
stagedActionIds = stagedActionIds.filter(id => {
const action = actionsById[id].action;
return (
whitelist && whitelist.indexOf(action.type) !== -1 ||
blacklist && blacklist.indexOf(action.type) === -1
);
stagedActionIds.forEach((id, idx) => {
if (this.isFiltered(rest.actionsById[id].action.type)) {
filteredStagedActionIds.push(id);
filteredComputedStates.push(computedStates[idx]);
}
});

rest = {
...rest,
stagedActionIds: stagedActionIds
stagedActionIds: filteredStagedActionIds,
computedStates: filteredComputedStates
};
} else {
rest = {
...rest,
stagedActionIds, computedStates
};
}

Expand Down

0 comments on commit baaf6a5

Please sign in to comment.