Skip to content

Commit

Permalink
feat(StoreDevtools): Allow custom serializer options (#1121)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-okrushko authored and brandonroberts committed Jun 13, 2018
1 parent fb9b172 commit 55a0488
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
21 changes: 20 additions & 1 deletion modules/store-devtools/spec/extension.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { unliftState } from '../src/utils';
function createOptions(
name: string = 'NgRx Store DevTools',
features: any = false,
serialize: boolean = false,
serialize: boolean | undefined = false,
maxAge: false | number = false
) {
const options: ReduxDevtoolsExtensionConfig = {
Expand Down Expand Up @@ -116,6 +116,25 @@ describe('DevtoolsExtension', () => {
expect(reduxDevtoolsExtension.connect).toHaveBeenCalledWith(options);
});

it('should connect with custom serializer', () => {
const customSerializer = {
replacer: (key: {}, value: any) => value,
};

devtoolsExtension = new DevtoolsExtension(
reduxDevtoolsExtension,
createConfig({
name: 'ngrx-store-devtool-todolist',
serialize: customSerializer,
})
);
// Subscription needed or else extension connection will not be established.
devtoolsExtension.actions$.subscribe(() => null);
expect(reduxDevtoolsExtension.connect).toHaveBeenCalledWith(
jasmine.objectContaining({ serialize: customSerializer })
);
});

describe('notify', () => {
it('should send notification with default options', () => {
devtoolsExtension = new DevtoolsExtension(
Expand Down
9 changes: 8 additions & 1 deletion modules/store-devtools/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ import { InjectionToken, Type } from '@angular/core';

export type ActionSanitizer = (action: Action, id: number) => Action;
export type StateSanitizer = (state: any, index: number) => any;
export type SerializationOptions = {
options?: boolean | any;
replacer?: (key: any, value: any) => {};
reviver?: (key: any, value: any) => {};
immutable?: any;
refs?: Array<any>;
};

export class StoreDevtoolsConfig {
maxAge: number | false;
monitor: ActionReducer<any, any>;
actionSanitizer?: ActionSanitizer;
stateSanitizer?: StateSanitizer;
name?: string;
serialize?: boolean;
serialize?: boolean | SerializationOptions;
logOnly?: boolean;
features?: any;
}
Expand Down
8 changes: 6 additions & 2 deletions modules/store-devtools/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { empty, Observable } from 'rxjs';
import { filter, map, share, switchMap, takeUntil } from 'rxjs/operators';

import { PERFORM_ACTION } from './actions';
import { STORE_DEVTOOLS_CONFIG, StoreDevtoolsConfig } from './config';
import {
SerializationOptions,
STORE_DEVTOOLS_CONFIG,
StoreDevtoolsConfig,
} from './config';
import { LiftedAction, LiftedState } from './reducer';
import {
sanitizeAction,
Expand Down Expand Up @@ -37,7 +41,7 @@ export interface ReduxDevtoolsExtensionConfig {
name: string | undefined;
instanceId: string;
maxAge?: number;
serialize?: boolean;
serialize?: boolean | SerializationOptions;
}

export interface ReduxDevtoolsExtension {
Expand Down

0 comments on commit 55a0488

Please sign in to comment.