Skip to content
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

Enhance Counter Slice Logic and Validation #2

Open
amar-jondhalekar opened this issue Nov 5, 2024 · 0 comments
Open

Enhance Counter Slice Logic and Validation #2

amar-jondhalekar opened this issue Nov 5, 2024 · 0 comments

Comments

@amar-jondhalekar
Copy link
Owner

Description:

Objective: Improve the counter slice by adding validation, handling edge cases, and enhancing readability.

Details:

  1. Input Validation for incrementByAmount:

    • Ensure that the incrementByAmount action only increments if the action.payload is a valid number.
    • Add validation to prevent invalid or non-numeric values from affecting the state.
  2. Edge Case Handling:

    • Add a minimum limit (e.g., 0) to prevent the value from going below zero when the decrement action is dispatched.
    • Optionally, set a maximum limit (e.g., 1000) to prevent the value from exceeding a specified threshold.
  3. Code Readability:

    • Add comments for each reducer function to explain the logic, especially the validation and edge case handling.
    • Refactor incrementByAmount to use parseInt or a similar function to safely parse numeric values.

Acceptance Criteria:

  • The incrementByAmount function only increments with valid numbers.
  • The counter cannot go below zero or above the maximum threshold.
  • Code is documented and clear, with comments explaining each reducer function.

Additional Notes:

  • Consider using utility functions to handle numeric parsing and validation.
  • Test cases should be created to cover edge cases, such as negative values and values exceeding the maximum.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant