Skip to content

Commit 1ecd658

Browse files
brandonrobertsMikeRyanDev
authored andcommitted
feat(StoreDevtools): Add option to configure extension in log-only mode (#712)
Closes #643, #374
1 parent fb8d2c6 commit 1ecd658

File tree

6 files changed

+36
-15
lines changed

6 files changed

+36
-15
lines changed

docs/store-devtools/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ import { environment } from '../environments/environment'; // Angular CLI enviro
3030
imports: [
3131
StoreModule.forRoot(reducers),
3232
// Instrumentation must be imported after importing StoreModule (config is optional)
33-
!environment.production ?
34-
StoreDevtoolsModule.instrument({
35-
maxAge: 25 // Retains last 25 states
36-
})
37-
: [],
33+
StoreDevtoolsModule.instrument({
34+
maxAge: 25 // Retains last 25 states,
35+
logOnly: environment.production // Restrict extension to log-only mode
36+
})
3837
]
3938
})
4039
export class AppModule { }
@@ -46,6 +45,9 @@ When you call the instrumentation, you can give an optional configuration object
4645
#### `maxAge`
4746
number (>1) | false - maximum allowed actions to be stored in the history tree. The oldest actions are removed once maxAge is reached. It's critical for performance. Default is `false` (infinite).
4847

48+
#### `logOnly`
49+
boolean - connect to the Devtools Extension in log-only mode. Default is `false` which enables all extension [features](https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/API/Arguments.md#features).
50+
4951
#### `name`
5052
string - the instance name to be showed on the monitor page. Default value is _NgRx Store DevTools_.
5153

example-app/app/app.module.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,10 @@ import { environment } from '../environments/environment';
6363
*
6464
* See: https://github.com/zalmoxisus/redux-devtools-extension
6565
*/
66-
!environment.production
67-
? StoreDevtoolsModule.instrument({
68-
name: 'NgRx Book Store DevTools',
69-
})
70-
: [],
66+
StoreDevtoolsModule.instrument({
67+
name: 'NgRx Book Store DevTools',
68+
logOnly: environment.production,
69+
}),
7170

7271
/**
7372
* EffectsModule.forRoot() is imported once in the root module and

modules/store-devtools/spec/extension.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ describe('DevtoolsExtension', () => {
3636
stateSanitizer: noStateSanitizer,
3737
name: 'NgRx Store DevTools',
3838
serialize: false,
39+
logOnly: false,
40+
features: false,
3941
};
4042
const action = {} as Action;
4143
const state = {} as LiftedState;
@@ -71,6 +73,8 @@ describe('DevtoolsExtension', () => {
7173
stateSanitizer: myStateSanitizer,
7274
name: 'ngrx-store-devtool-todolist',
7375
serialize: false,
76+
logOnly: false,
77+
features: false,
7478
};
7579
const action = {} as Action;
7680
const state = {} as LiftedState;

modules/store-devtools/src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export class StoreDevtoolsConfig {
88
stateSanitizer?: <S>(state: S, index: number) => S;
99
name?: string;
1010
serialize?: boolean;
11+
logOnly?: boolean;
12+
features?: any;
1113
}
1214

1315
export const STORE_DEVTOOLS_CONFIG = new InjectionToken<StoreDevtoolsConfig>(

modules/store-devtools/src/extension.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,18 @@ export interface ReduxDevtoolsExtensionConnection {
2727
subscribe(listener: (change: any) => void): void;
2828
unsubscribe(): void;
2929
send(action: any, state: any): void;
30+
init(state?: any): void;
31+
}
32+
export interface ReduxDevtoolsExtensionConfig {
33+
features?: object | boolean;
34+
name: string | undefined;
35+
instanceId: string;
3036
}
3137

3238
export interface ReduxDevtoolsExtension {
33-
connect(options: {
34-
shouldStringify?: boolean;
35-
instanceId: string;
36-
}): ReduxDevtoolsExtensionConnection;
39+
connect(
40+
options: ReduxDevtoolsExtensionConfig
41+
): ReduxDevtoolsExtensionConnection;
3742
send(
3843
action: any,
3944
state: any,
@@ -74,7 +79,10 @@ export class DevtoolsExtension {
7479
return new Observable(subscriber => {
7580
const connection = this.devtoolsExtension.connect({
7681
instanceId: this.instanceId,
82+
name: this.config.name,
83+
features: this.config.features,
7784
});
85+
connection.init();
7886

7987
connection.subscribe((change: any) => subscriber.next(change));
8088

modules/store-devtools/src/instrument.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,16 @@ export function createConfig(
8484
stateSanitizer: noStateSanitizer,
8585
name: DEFAULT_NAME,
8686
serialize: false,
87+
logOnly: false,
88+
features: false,
8789
};
8890

8991
let options = typeof _options === 'function' ? _options() : _options;
90-
const config = Object.assign({}, DEFAULT_OPTIONS, options);
92+
const logOnly = options.logOnly
93+
? { pause: true, export: true, test: true }
94+
: false;
95+
const features = options.features || logOnly;
96+
const config = Object.assign({}, DEFAULT_OPTIONS, { features }, options);
9197

9298
if (config.maxAge && config.maxAge < 2) {
9399
throw new Error(

0 commit comments

Comments
 (0)