Filtering actions by predicate
See original GitHub issueCurrently we seem to have two options for filtering actions - actionsWhitelist
and actionsBlacklist
- which can handle globs and regular expressions.
This allows only for filtering on action types.
It would be very helpful to have a config option like redux-logger’s predicate that allows for more complex filtering based on action payload and/or current state. For example:
predicate: (getState, action) => getState().dev.logLevel === VERBOSE && !action.forwarded
As a workaround (without access to state) I tried something like this:
{
actionsFilter : action => predicate(action) ? action : {type: 'BLACKLISTED'},
actionsBlacklist: ['BLACKLISTED']
}
But that didn’t work out. It would seem the execution order is working against me, i.e. the blacklist is applied before the transform.
Perhaps you can think of another workaround?
Alternatively you could use the existing actionsFilter
config option and modify it so that it doesn’t log anything when the function returns false
. You’d need to pass the state or a getState()
function as the third argument to remain backwards compatible. (Personally I’m not a fan of mixed return types though)
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
@RIAstar, I’ve implemented the
predicate
parameter and will publish a new version to Chrome Store tomorrow. Meanwhile, you can amend the changes (especially docs).Works like a charm. Thank you.