Skip to content

Commit 698bd29

Browse files
feat(store-devtools): add autoPause option (#2941)
Closes #2722
1 parent 5102a34 commit 698bd29

File tree

8 files changed

+27
-2
lines changed

8 files changed

+27
-2
lines changed

modules/store-devtools/schematics/ng-add/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
"type": "number",
3232
"default": 25,
3333
"description": "number (>1) | 0 - maximum allowed actions to be stored in the history tree. The oldest actions are removed once maxAge is reached. It's critical for performance. 0 is infinite. Default is 25 for performance reasons."
34+
},
35+
"autoPause": {
36+
"type": "boolean",
37+
"default": false,
38+
"description": "boolean - pauses recording actions and state changes when the extension window is not open."
3439
}
3540
},
3641
"required": []

modules/store-devtools/schematics/ng-add/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export interface Schema {
44
project?: string;
55
module?: string;
66
maxAge?: number;
7+
autoPause?: boolean;
78
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe('StoreDevtoolsOptions', () => {
2626
name: DEFAULT_NAME,
2727
serialize: false,
2828
logOnly: false,
29+
autoPause: false,
2930
features: defaultFeatures,
3031
});
3132
});
@@ -43,6 +44,7 @@ describe('StoreDevtoolsOptions', () => {
4344
stateSanitizer,
4445
name: 'ABC',
4546
serialize: true,
47+
autoPause: true,
4648
features: {
4749
test: true,
4850
},
@@ -55,6 +57,7 @@ describe('StoreDevtoolsOptions', () => {
5557
name: 'ABC',
5658
serialize: true,
5759
logOnly: false,
60+
autoPause: true,
5861
features: {
5962
test: true,
6063
},
@@ -71,6 +74,7 @@ describe('StoreDevtoolsOptions', () => {
7174
name: DEFAULT_NAME,
7275
serialize: false,
7376
logOnly: false,
77+
autoPause: false,
7478
features: defaultFeatures,
7579
});
7680
});
@@ -87,6 +91,7 @@ describe('StoreDevtoolsOptions', () => {
8791
name: DEFAULT_NAME,
8892
serialize: false,
8993
logOnly: true,
94+
autoPause: false,
9095
features: {
9196
pause: true,
9297
export: true,

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ function createOptions(
2525
test: true,
2626
},
2727
serialize: boolean | undefined = false,
28-
maxAge: false | number = false
28+
maxAge: false | number = false,
29+
autoPause: boolean = false
2930
) {
3031
const options: ReduxDevtoolsExtensionConfig = {
3132
name,
3233
features,
3334
serialize,
35+
autoPause,
3436
};
3537
if (maxAge !== false /* support === 0 */) {
3638
options.maxAge = maxAge;
@@ -115,6 +117,7 @@ describe('DevtoolsExtension', () => {
115117
name: 'ngrx-store-devtool-todolist',
116118
maxAge: 10,
117119
serialize: true,
120+
autoPause: true,
118121
// these two should not be added
119122
actionSanitizer: myActionSanitizer,
120123
stateSanitizer: myStateSanitizer,
@@ -127,7 +130,8 @@ describe('DevtoolsExtension', () => {
127130
'ngrx-store-devtool-todolist',
128131
undefined,
129132
true,
130-
10
133+
10,
134+
true
131135
);
132136
expect(reduxDevtoolsExtension.connect).toHaveBeenCalledWith(options);
133137
});

modules/store-devtools/src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export class StoreDevtoolsConfig {
3636
actionsBlocklist?: string[];
3737
actionsSafelist?: string[];
3838
predicate?: Predicate;
39+
autoPause?: boolean;
3940
}
4041

4142
export const STORE_DEVTOOLS_CONFIG = new InjectionToken<StoreDevtoolsConfig>(
@@ -66,6 +67,7 @@ export function createConfig(
6667
name: DEFAULT_NAME,
6768
serialize: false,
6869
logOnly: false,
70+
autoPause: false,
6971
// Add all features explicitly. This prevent buggy behavior for
7072
// options like "lock" which might otherwise not show up.
7173
features: {

modules/store-devtools/src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export interface ReduxDevtoolsExtensionConfig {
5454
features?: object | boolean;
5555
name: string | undefined;
5656
maxAge?: number;
57+
autoPause?: boolean;
5758
serialize?: boolean | SerializationOptions;
5859
}
5960

@@ -241,6 +242,7 @@ export class DevtoolsExtension {
241242
name: config.name,
242243
features: config.features,
243244
serialize: config.serialize,
245+
autoPause: config.autoPause ?? false,
244246
// The action/state sanitizers are not added to the config
245247
// because sanitation is done in this class already.
246248
// It is done before sending it to the devtools extension for consistency:

projects/ngrx.io/content/guide/store-devtools/config.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ number (>1) | `false` - maximum allowed actions to be stored in the history tree
1212

1313
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).
1414

15+
### `autoPause`
16+
17+
boolean - Pauses recording actions and state changes when the extension window is not open. Default is `false`.
18+
1519
### `name`
1620

1721
string - the instance name to show on the monitor page. Default value is NgRx Store DevTools.
@@ -75,6 +79,7 @@ features: {
7579
StoreDevtoolsModule.instrument({
7680
maxAge: 25,
7781
logOnly: false,
82+
autoPause: true,
7883
features: {
7984
pause: false,
8085
lock: true,

projects/ngrx.io/content/guide/store-devtools/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { environment } from '../environments/environment'; // Angular CLI enviro
2525
StoreDevtoolsModule.instrument({
2626
maxAge: 25, // Retains last 25 states
2727
logOnly: environment.production, // Restrict extension to log-only mode
28+
autoPause: true, // Pauses recording actions and state changes when the extension window is not open
2829
}),
2930
],
3031
})

0 commit comments

Comments
 (0)