Skip to content

Commit 5ec2d71

Browse files
feat(ui): make debug logger middleware configurable
While troubleshooting an issue with this middleware, I found the inclusion of the nextState and diff to be very noisy. It's now a function that accepts some options to configure the output, and returns the middleware.
1 parent 8f28903 commit 5ec2d71

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

invokeai/frontend/web/src/app/store/middleware/debugLoggerMiddleware.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@ import { diff } from 'jsondiffpatch';
77
/**
88
* Super simple logger middleware. Useful for debugging when the redux devtools are awkward.
99
*/
10-
export const debugLoggerMiddleware: Middleware = (api: MiddlewareAPI) => (next) => (action) => {
11-
const originalState = api.getState();
12-
console.log('REDUX: dispatching', action);
13-
const result = next(action);
14-
const nextState = api.getState();
15-
console.log('REDUX: next state', nextState);
16-
console.log('REDUX: diff', diff(originalState, nextState));
17-
return result;
18-
};
10+
export const getDebugLoggerMiddleware =
11+
(options?: { withDiff?: boolean; withNextState?: boolean }): Middleware =>
12+
(api: MiddlewareAPI) =>
13+
(next) =>
14+
(action) => {
15+
const originalState = api.getState();
16+
console.log('REDUX: dispatching', action);
17+
const result = next(action);
18+
const nextState = api.getState();
19+
if (options?.withNextState) {
20+
console.log('REDUX: next state', nextState);
21+
}
22+
if (options?.withDiff) {
23+
console.log('REDUX: diff', diff(originalState, nextState));
24+
}
25+
return result;
26+
};

0 commit comments

Comments
 (0)