Skip to content
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

added action action and state sanitizer #494 #786

Closed
Closed
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
21 changes: 21 additions & 0 deletions modules/store-devtools/spec/config.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ActionReducer, Action } from '@ngrx/store';
import { StoreDevtoolsConfig } from '../';

describe('StoreDevtoolsOptions', () => {
it('can be initialized with actionSanitizer', () => {
const options = new StoreDevtoolsConfig();
function sanitizer(action: Action, id: number): Action {
return action;
}
options.actionSanitizer = sanitizer;
expect(options.actionSanitizer).toEqual(sanitizer);
});
it('can be initialized with stateSanitizer', () => {
const options = new StoreDevtoolsConfig();
function stateSanitizer(state: any, index: number): any {
return state;
}
options.actionSanitizer = stateSanitizer;
expect(options.actionSanitizer).toEqual(stateSanitizer);
});
});
4 changes: 3 additions & 1 deletion modules/store-devtools/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { ActionReducer } from '@ngrx/store';
import { ActionReducer, Action } from '@ngrx/store';
import { InjectionToken, Type } from '@angular/core';

export class StoreDevtoolsConfig {
maxAge: number | false;
monitor: ActionReducer<any, any>;
actionSanitizer?: <A extends Action>(action: A, id: number) => A;
stateSanitizer?: <S>(state: S, index: number) => S;
}

export const STORE_DEVTOOLS_CONFIG = new InjectionToken<StoreDevtoolsConfig>(
Expand Down
10 changes: 10 additions & 0 deletions modules/store-devtools/src/instrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,22 @@ export function noMonitor(): null {
return null;
}

export function noActionSanitizer(): null {
return null;
}

export function noStateSanitizer(): null {
return null;
}

export function createConfig(
_options: StoreDevtoolsOptions
): StoreDevtoolsConfig {
const DEFAULT_OPTIONS: StoreDevtoolsConfig = {
maxAge: false,
monitor: noMonitor,
actionSanitizer: noActionSanitizer,
stateSanitizer: noStateSanitizer,
};

let options = typeof _options === 'function' ? _options() : _options;
Expand Down