korbit-ai[bot] commented on code in PR #32795:
URL: https://github.com/apache/superset/pull/32795#discussion_r2008048009
##########
superset-frontend/src/middleware/loggerMiddleware.js:
##########
@@ -67,78 +70,87 @@ const logMessageQueue = new DebouncedMessageQueue({
delayThreshold: 1000,
});
let lastEventId = 0;
-const loggerMiddleware = store => next => action => {
- if (action.type !== LOG_EVENT) {
- return next(action);
- }
+const loggerMiddleware = store => next => {
+ let navPath;
Review Comment:
### Global Mutable State <sub></sub>
<details>
<summary>Tell me more</summary>
###### What is the issue?
The middleware uses mutable global state (lastEventId and effectively
navPath) which makes the code harder to reason about and test.
###### Why this matters
Global mutable state can lead to unexpected behavior, makes testing
difficult, and violates principles of functional programming that Redux
typically encourages.
###### Suggested change ∙ *Feature Preview*
Encapsulate the state within a closure or class:
```javascript
const createLoggerMiddleware = () => {
let lastEventId = 0;
let navPath = null;
return store => next => action => {
// middleware logic
};
};
export default createLoggerMiddleware();
```
###### Provide feedback to improve future suggestions
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/327566c3-4caf-4f4b-8687-6017689d12df/upvote)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/327566c3-4caf-4f4b-8687-6017689d12df?what_not_true=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/327566c3-4caf-4f4b-8687-6017689d12df?what_out_of_scope=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/327566c3-4caf-4f4b-8687-6017689d12df?what_not_in_standard=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/327566c3-4caf-4f4b-8687-6017689d12df)
</details>
<sub>
💬 Looking for more details? Reply to this comment to chat with Korbit.
</sub>
<!--- korbi internal id:716d33f3-5502-473f-ad81-f2ada93c60b4 -->
[](716d33f3-5502-473f-ad81-f2ada93c60b4)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]