Skip to content

Added action filtering by function #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
"type": "git",
"url": "git+https://github.com/btroncone/ngrx-store-logger.git"
},
"keywords": ["redux", "ngrx", "store", "logger", "middleware", "rxjs"],
"keywords": [
"redux",
"ngrx",
"store",
"logger",
"middleware",
"rxjs"
],
"author": "Brian Troncone",
"license": "MIT",
"bugs": {
Expand Down
8 changes: 5 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ const isAllowed = (action, filter) => {
if (!filter) {
return true;
}
if(typeof filter === 'function') return filter(action.type);
if (filter.whitelist && filter.whitelist.length) {
return filter.whitelist.indexOf(action.type) !== -1;
}
Expand Down Expand Up @@ -256,7 +257,7 @@ export interface LoggerOptions {
* Print timestamp with action? default: true
*/
timestamp?: boolean;
filter?: LoggerFilterOption;
filter?: LoggerFilterOption | ActionFilter;
/**
* Transform state before print default: state => state
*/
Expand All @@ -268,15 +269,16 @@ export interface LoggerOptions {
colors?: LoggerColorsOption;
}

export type ActionFilter = (type: string) => boolean;
export interface LoggerFilterOption {
/**
* Only print actions included in this list - has priority over blacklist
*/
whitelist?: string[];
whitelist?: Array<string>;
/**
* Only print actions that are NOT included in this list
*/
blacklist?: string[];
blacklist?: Array<string>;
}

export interface LoggerColorsOption {
Expand Down