mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2024-11-22 09:36:43 +03:00
Exclude instrumentation calls from stack trace
This commit is contained in:
parent
ee439fac9f
commit
d94c034f07
|
@ -23,7 +23,7 @@ export const ActionTypes = {
|
||||||
* Action creators to change the History state.
|
* Action creators to change the History state.
|
||||||
*/
|
*/
|
||||||
export const ActionCreators = {
|
export const ActionCreators = {
|
||||||
performAction(action, trace) {
|
performAction(action, trace, toExcludeFromTrace) {
|
||||||
if (!isPlainObject(action)) {
|
if (!isPlainObject(action)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Actions must be plain objects. ' +
|
'Actions must be plain objects. ' +
|
||||||
|
@ -39,9 +39,15 @@ export const ActionCreators = {
|
||||||
}
|
}
|
||||||
|
|
||||||
let stack;
|
let stack;
|
||||||
|
let error;
|
||||||
if (trace) {
|
if (trace) {
|
||||||
if (typeof trace === 'function') stack = trace(action);
|
if (typeof trace === 'function') stack = trace(action);
|
||||||
else stack = Error().stack;
|
else {
|
||||||
|
error = Error();
|
||||||
|
// https://v8.dev/docs/stack-trace-api#stack-trace-collection-for-custom-exceptions
|
||||||
|
if (Error.captureStackTrace) Error.captureStackTrace(error, toExcludeFromTrace);
|
||||||
|
stack = error.stack;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { type: ActionTypes.PERFORM_ACTION, action, timestamp: Date.now(), stack };
|
return { type: ActionTypes.PERFORM_ACTION, action, timestamp: Date.now(), stack };
|
||||||
|
@ -191,8 +197,8 @@ function recomputeStates(
|
||||||
/**
|
/**
|
||||||
* Lifts an app's action into an action on the lifted store.
|
* Lifts an app's action into an action on the lifted store.
|
||||||
*/
|
*/
|
||||||
export function liftAction(action, trace) {
|
export function liftAction(action, trace, toExcludeFromTrace) {
|
||||||
return ActionCreators.performAction(action, trace);
|
return ActionCreators.performAction(action, trace, toExcludeFromTrace);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -614,7 +620,7 @@ export function unliftStore(liftedStore, liftReducer, options) {
|
||||||
liftedStore,
|
liftedStore,
|
||||||
|
|
||||||
dispatch(action) {
|
dispatch(action) {
|
||||||
liftedStore.dispatch(liftAction(action, trace));
|
liftedStore.dispatch(liftAction(action, trace, this.dispatch));
|
||||||
return action;
|
return action;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -710,8 +710,7 @@ describe('instrument', () => {
|
||||||
expect(exportedState.actionsById[0].stack).toBe(undefined);
|
expect(exportedState.actionsById[0].stack).toBe(undefined);
|
||||||
expect(exportedState.actionsById[1].stack).toBeA('string');
|
expect(exportedState.actionsById[1].stack).toBeA('string');
|
||||||
expect(exportedState.actionsById[1].stack).toMatch(/^Error/);
|
expect(exportedState.actionsById[1].stack).toMatch(/^Error/);
|
||||||
expect(exportedState.actionsById[1].stack).toContain('at Object.performAction');
|
expect(exportedState.actionsById[1].stack).toNotMatch(/instrument.js/);
|
||||||
expect(exportedState.actionsById[1].stack).toContain('instrument.js');
|
|
||||||
expect(exportedState.actionsById[1].stack).toContain('instrument.spec.js');
|
expect(exportedState.actionsById[1].stack).toContain('instrument.spec.js');
|
||||||
expect(exportedState.actionsById[1].stack).toContain('/mocha/');
|
expect(exportedState.actionsById[1].stack).toContain('/mocha/');
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user