-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement useReducer for Comment State Management (React commenting) #9801
Conversation
/* eslint-disable complexity */ | ||
import { makeDeepCopy } from "./helpers"; | ||
|
||
const reducer = (state, action) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function reducer
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
/* eslint-disable complexity */ | ||
import { makeDeepCopy } from "./helpers"; | ||
|
||
const reducer = (state, action) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function reducer
has 39 lines of code (exceeds 25 allowed). Consider refactoring.
@@ -0,0 +1,50 @@ | |||
/* eslint-disable complexity */ | |||
import { makeDeepCopy } from "./helpers"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parsing error: 'import' and 'export' may appear only with 'sourceType: module'
Code Climate has analyzed commit 7e76038 and detected 4 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
Codecov Report
@@ Coverage Diff @@
## main #9801 +/- ##
=======================================
Coverage ? 82.07%
=======================================
Files ? 98
Lines ? 5940
Branches ? 0
=======================================
Hits ? 4875
Misses ? 1065
Partials ? 0 |
Ready to merge! Tests pass. Asking for an override on the codeclimate issues :) |
Fantastic work, @noi5e, thank you! |
Part of a React rewrite of the commenting system, see #9365 for more context.
In this PR, I begin to switch state management from React's useState hook to useReducer instead.
useReducer
is modeled after other React state management libraries like Redux.Why the switch? The app state is starting to get very complex, and will only get more complex as features are added. For example, let's take the example of "disable submit comment button after user clicks on it, and before server sends a response". This is a feature which I'm going to start work on soon, and it will require adding more variables into state:
waitingForServerResponse
,submitButtonIsDisabled
, and the like.Switching over to
useReducer
will make this codebase easier to understand and debug in the long run.I've created a new
reducers.js
file. Everything the app does that changes state will be described in this file. For now, it looks like this:(This issue is part of the larger Comment Editor Overhaul Project with Outreachy. Refer to Planning Issue #9069 for more context)