From 3b6da60bc24794c14ccc4558f366cd954134d890 Mon Sep 17 00:00:00 2001 From: roopkt Date: Sat, 21 Oct 2017 08:40:26 -0400 Subject: [PATCH] added action action and state sanitizer #494 --- modules/store-devtools/spec/config.spec.ts | 21 +++++++++++++++++++++ modules/store-devtools/src/config.ts | 4 +++- modules/store-devtools/src/instrument.ts | 10 ++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 modules/store-devtools/spec/config.spec.ts diff --git a/modules/store-devtools/spec/config.spec.ts b/modules/store-devtools/spec/config.spec.ts new file mode 100644 index 0000000000..a730dd007f --- /dev/null +++ b/modules/store-devtools/spec/config.spec.ts @@ -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); + }); +}); diff --git a/modules/store-devtools/src/config.ts b/modules/store-devtools/src/config.ts index 7d2a8f7558..d31c2adf8e 100644 --- a/modules/store-devtools/src/config.ts +++ b/modules/store-devtools/src/config.ts @@ -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; + actionSanitizer?: (action: A, id: number) => A; + stateSanitizer?: (state: S, index: number) => S; } export const STORE_DEVTOOLS_CONFIG = new InjectionToken( diff --git a/modules/store-devtools/src/instrument.ts b/modules/store-devtools/src/instrument.ts index 101e77479c..56be93202c 100644 --- a/modules/store-devtools/src/instrument.ts +++ b/modules/store-devtools/src/instrument.ts @@ -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;