mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-07-22 14:09:46 +03:00
Pass action to trace (#1100)
This commit is contained in:
parent
0bf0c4e30f
commit
b058901129
|
@ -222,10 +222,11 @@ function post<S, A extends Action<unknown>>(
|
||||||
|
|
||||||
function getStackTrace(
|
function getStackTrace(
|
||||||
config: Config,
|
config: Config,
|
||||||
toExcludeFromTrace: Function | undefined
|
toExcludeFromTrace: Function | undefined,
|
||||||
|
action: Action<unknown>
|
||||||
) {
|
) {
|
||||||
if (!config.trace) return undefined;
|
if (!config.trace) return undefined;
|
||||||
if (typeof config.trace === 'function') return config.trace();
|
if (typeof config.trace === 'function') return config.trace(action);
|
||||||
|
|
||||||
let stack;
|
let stack;
|
||||||
let extraFrames = 0;
|
let extraFrames = 0;
|
||||||
|
@ -268,16 +269,33 @@ function amendActionType<A extends Action<unknown>>(
|
||||||
toExcludeFromTrace: Function | undefined
|
toExcludeFromTrace: Function | undefined
|
||||||
): StructuralPerformAction<A> {
|
): StructuralPerformAction<A> {
|
||||||
let timestamp = Date.now();
|
let timestamp = Date.now();
|
||||||
let stack = getStackTrace(config, toExcludeFromTrace);
|
|
||||||
if (typeof action === 'string') {
|
if (typeof action === 'string') {
|
||||||
return { action: { type: action } as A, timestamp, stack };
|
const amendedAction = { type: action } as A;
|
||||||
|
return {
|
||||||
|
action: amendedAction,
|
||||||
|
timestamp,
|
||||||
|
stack: getStackTrace(config, toExcludeFromTrace, amendedAction),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
if (!(action as A).type)
|
if (!(action as A).type) {
|
||||||
return { action: { type: 'update' } as A, timestamp, stack };
|
const amendedAction = { type: 'update' } as A;
|
||||||
if ((action as StructuralPerformAction<A>).action)
|
return {
|
||||||
|
action: amendedAction,
|
||||||
|
timestamp,
|
||||||
|
stack: getStackTrace(config, toExcludeFromTrace, amendedAction),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if ((action as StructuralPerformAction<A>).action) {
|
||||||
|
const stack = getStackTrace(
|
||||||
|
config,
|
||||||
|
toExcludeFromTrace,
|
||||||
|
(action as StructuralPerformAction<A>).action
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
stack ? { stack, ...action } : action
|
stack ? { stack, ...action } : action
|
||||||
) as StructuralPerformAction<A>;
|
) as StructuralPerformAction<A>;
|
||||||
|
}
|
||||||
|
const stack = getStackTrace(config, toExcludeFromTrace, action as A);
|
||||||
return { action, timestamp, stack } as StructuralPerformAction<A>;
|
return { action, timestamp, stack } as StructuralPerformAction<A>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,9 @@ export interface ConfigWithExpandedMaxAge {
|
||||||
currentLiftedAction: LiftedAction<S, A, unknown>,
|
currentLiftedAction: LiftedAction<S, A, unknown>,
|
||||||
previousLiftedState: LiftedState<S, A, unknown> | undefined
|
previousLiftedState: LiftedState<S, A, unknown> | undefined
|
||||||
) => number);
|
) => number);
|
||||||
readonly trace?: boolean | (() => string | undefined);
|
readonly trace?:
|
||||||
|
| boolean
|
||||||
|
| (<A extends Action<unknown>>(action: A) => string | undefined);
|
||||||
readonly traceLimit?: number;
|
readonly traceLimit?: number;
|
||||||
readonly shouldCatchErrors?: boolean;
|
readonly shouldCatchErrors?: boolean;
|
||||||
readonly shouldHotReload?: boolean;
|
readonly shouldHotReload?: boolean;
|
||||||
|
|
|
@ -216,14 +216,15 @@ export function getSeralizeParameter(
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getStackTrace(
|
export function getStackTrace<A extends Action<unknown>>(
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
config: { trace?: () => {}; traceLimit: number },
|
config: { trace?: (action?: A) => {}; traceLimit: number },
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
toExcludeFromTrace?: Function | undefined
|
toExcludeFromTrace?: Function | undefined,
|
||||||
|
action?: A
|
||||||
) {
|
) {
|
||||||
if (!config.trace) return undefined;
|
if (!config.trace) return undefined;
|
||||||
if (typeof config.trace === 'function') return config.trace();
|
if (typeof config.trace === 'function') return config.trace(action);
|
||||||
|
|
||||||
let stack;
|
let stack;
|
||||||
let extraFrames = 0;
|
let extraFrames = 0;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user