Skip to content
This repository has been archived by the owner on Sep 24, 2020. It is now read-only.

Alternative code optimization #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mnp-mid
Copy link

@mnp-mid mnp-mid commented Apr 30, 2018

Extracted switch case code into multiple methods

@MichaelKaaden
Copy link
Owner

That isn't an optimization. Effectively, it hides what a switch makes clearly visible.

@mnp-mid
Copy link
Author

mnp-mid commented Apr 30, 2018

The benefit of having methods instead of a switch case is that you are able to use inheritance at any time and overwrite a single method. This may bring some flexibility in future, if required.

Additionally, a method is encapsuled in it's own and not interfering with other case definitions. So variables with the same name doesn't need to be defined out side the switch case.

Besides it would fit into the open/closed principle. Open for extensions, but closed for modifications.

@MichaelKaaden
Copy link
Owner

Simply no. You don't override anything in a reducer. Using multiple implementations here would be completely wrong. I see your point regarding variables, but if you really need to do so much logic, it probably would have been better put inside the ActionCreator.
Remember: A reducer is a pure function, not a complicated class construct.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants