Skip to content

Commit 187802a

Browse files
authored
feat(store-devtools): add redux dev tool trace support (#3517) (#3665)
Closes #3517 Closes #1868
1 parent 852d40e commit 187802a

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ describe('StoreDevtoolsOptions', () => {
2828
logOnly: false,
2929
autoPause: false,
3030
features: defaultFeatures,
31+
trace: false,
32+
traceLimit: 75,
3133
});
3234
});
3335

@@ -45,6 +47,8 @@ describe('StoreDevtoolsOptions', () => {
4547
name: 'ABC',
4648
serialize: true,
4749
autoPause: true,
50+
trace: true,
51+
traceLimit: 20,
4852
features: {
4953
test: true,
5054
},
@@ -58,6 +62,8 @@ describe('StoreDevtoolsOptions', () => {
5862
serialize: true,
5963
logOnly: false,
6064
autoPause: true,
65+
trace: true,
66+
traceLimit: 20,
6167
features: {
6268
test: true,
6369
},
@@ -75,6 +81,8 @@ describe('StoreDevtoolsOptions', () => {
7581
serialize: false,
7682
logOnly: false,
7783
autoPause: false,
84+
trace: false,
85+
traceLimit: 75,
7886
features: defaultFeatures,
7987
});
8088
});
@@ -92,6 +100,8 @@ describe('StoreDevtoolsOptions', () => {
92100
serialize: false,
93101
logOnly: true,
94102
autoPause: false,
103+
trace: false,
104+
traceLimit: 75,
95105
features: {
96106
pause: true,
97107
export: true,

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@ function createOptions(
2626
},
2727
serialize: boolean | undefined = false,
2828
maxAge: false | number = false,
29-
autoPause: boolean = false
29+
autoPause: boolean = false,
30+
trace: boolean = false,
31+
traceLimit: number = 75
3032
) {
3133
const options: ReduxDevtoolsExtensionConfig = {
3234
name,
3335
features,
3436
serialize,
3537
autoPause,
38+
trace,
39+
traceLimit,
3640
};
3741
if (maxAge !== false /* support === 0 */) {
3842
options.maxAge = maxAge;
@@ -121,6 +125,8 @@ describe('DevtoolsExtension', () => {
121125
// these two should not be added
122126
actionSanitizer: myActionSanitizer,
123127
stateSanitizer: myStateSanitizer,
128+
trace: true,
129+
traceLimit: 20,
124130
}),
125131
<any>null
126132
);
@@ -131,7 +137,9 @@ describe('DevtoolsExtension', () => {
131137
undefined,
132138
true,
133139
10,
134-
true
140+
true,
141+
true,
142+
20
135143
);
136144
expect(reduxDevtoolsExtension.connect).toHaveBeenCalledWith(options);
137145
});

modules/store-devtools/src/config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ export class StoreDevtoolsConfig {
104104
* Auto pauses when the extension’s window is not opened, and so has zero impact on your app when not in use.
105105
*/
106106
autoPause?: boolean;
107+
108+
/**
109+
* If set to true, will include stack trace for every dispatched action
110+
*/
111+
trace?: boolean | (() => string);
112+
113+
/**
114+
* Maximum stack trace frames to be stored (in case trace option was provided as true).
115+
*/
116+
traceLimit?: number;
107117
}
108118

109119
export const STORE_DEVTOOLS_CONFIG = new InjectionToken<StoreDevtoolsConfig>(
@@ -139,6 +149,8 @@ export function createConfig(
139149
serialize: false,
140150
logOnly: false,
141151
autoPause: false,
152+
trace: false,
153+
traceLimit: 75,
142154
// Add all features explicitly. This prevent buggy behavior for
143155
// options like "lock" which might otherwise not show up.
144156
features: {

modules/store-devtools/src/extension.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ export interface ReduxDevtoolsExtensionConfig {
5757
maxAge?: number;
5858
autoPause?: boolean;
5959
serialize?: boolean | SerializationOptions;
60+
trace?: boolean | (() => string);
61+
traceLimit?: number;
6062
}
6163

6264
export interface ReduxDevtoolsExtension {
@@ -244,6 +246,8 @@ export class DevtoolsExtension {
244246
features: config.features,
245247
serialize: config.serialize,
246248
autoPause: config.autoPause ?? false,
249+
trace: config.trace ?? false,
250+
traceLimit: config.traceLimit ?? 75,
247251
// The action/state sanitizers are not added to the config
248252
// because sanitation is done in this class already.
249253
// It is done before sending it to the devtools extension for consistency:

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ import { environment } from '../environments/environment'; // Angular CLI enviro
2727
maxAge: 25, // Retains last 25 states
2828
logOnly: !isDevMode(), // Restrict extension to log-only mode
2929
autoPause: true, // Pauses recording actions and state changes when the extension window is not open
30+
trace: false, // If set to true, will include stack trace for every dispatched action, so you can see it in trace tab jumping directly to that part of code
31+
traceLimit: 75, // maximum stack trace frames to be stored (in case trace option was provided as true)
3032
}),
3133
],
3234
})
3335
export class AppModule {}
3436
</code-example>
37+
38+
> More extension options and explanation, refer to [Redux Devtools Documentation](https://github.com/reduxjs/redux-devtools#documentation)

0 commit comments

Comments
 (0)