Refactor countdown hook to use enum for status management #38
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I hope this message finds you well.
While looking for a library, your repository caught my eye, and I found a place where I think I could help. I believe there could be a better version of the 'src/countdown.tsx' file. With your permission, let me explain why I think so and what I have done as a solution.
Firstly, the four main values(
isActive
,isInactive
,isRunning
,isPaused
) in the file are a bit confusing and change together every time, which didn't feel quite right to me. Let me give you an example.These two lines are simply the opposite of each other; we can use
!isActive
where we want to useisInactive
.If we make this change, our variable count will decrease from 4 to 3, Good, we've reduced one value, but I believe we can do even better.
The
isActive
value is actually a value that checks whether theisRunning
orisPaused
value is true. Then, we do not need theisActive
value either. Actually, the four values(isActive
,isInactive
,isRunning
,isPaused
) we are export are essentially just an interpretation. Let's just keep a single value and change it, and finally, we can find the other values(isActive
,isInactive
,isRunning
,isPaused
) by interpreting this value.We need just one status and an enum to help us with this matter. Let's refactor the lines where the four values change into a state where only a single value changes, with the help of enums.
After making these changes, when we look at the code, instead of four values changing at the same time, there's only one value, and it's not a value like false or true, but a value we can read like English.
I've run the test "npm run test" all 20 test is successful.
I'm curious about your thoughts on this topic and the changes,
Take care of yourself.