From 006109245597e63bbd50eeec9da5a204b7f13b88 Mon Sep 17 00:00:00 2001 From: wwladislavv Date: Wed, 2 Aug 2017 14:27:47 +0300 Subject: [PATCH] fixed feature#10 for custom-actions-filter --- .gitignore | 1 + src/FilterMonitor.js | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index b7a60ee..b19a890 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ node_modules lib coverage .idea +package-lock.json \ No newline at end of file diff --git a/src/FilterMonitor.js b/src/FilterMonitor.js index 5ce5109..0ca3d37 100644 --- a/src/FilterMonitor.js +++ b/src/FilterMonitor.js @@ -9,15 +9,18 @@ export default class FilterMonitor extends Component { static propTypes = { children: PropTypes.element, whitelist: PropTypes.array, - blacklist: PropTypes.array + blacklist: PropTypes.array, + actionsPredicate: PropTypes.func }; - isNotFiltered(actionType) { - const type = actionType || ''; - return ( - this.props.whitelist && type.match(this.props.whitelist.join('|')) || - this.props.blacklist && !type.match(this.props.blacklist.join('|')) - ); + static defaultProps = { + actionsPredicate: (action, whitelist, blacklist) => { + const type = action.type || ''; + return ( + whitelist && type.match(whitelist.join('|')) || + blacklist && !type.match(blacklist.join('|')) + ); + } } render() { @@ -32,7 +35,7 @@ export default class FilterMonitor extends Component { if (whitelist || blacklist) { stagedActionIds.forEach((id, idx) => { - if (this.isNotFiltered(actionsById[id].action.type)) { + if (this.props.actionsPredicate(actionsById[id].action, whitelist, blacklist)) { filteredStagedActionIds.push(id); filteredComputedStates.push( statesFilter ?