-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
js_stateful-object solution #2704
base: master
Are you sure you want to change the base?
Conversation
src/transformState.js
Outdated
const actionType = action.type; | ||
const actionExtraData = action.extraData; | ||
const actionKeysToRemove = action.keysToRemove; |
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.
don't see any sense to create these redundant constants
src/transformState.js
Outdated
if (actionType === 'addProperties') { | ||
Object.assign(state, actionExtraData); | ||
} | ||
|
||
if (actionType === 'removeProperties') { | ||
for (const property of actionKeysToRemove) { | ||
delete state[property]; | ||
} | ||
} | ||
|
||
if (actionType === 'clear') { | ||
for (const element in state) { | ||
delete state[element]; | ||
} |
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.
it's better to use a switch case statement when you have multiple conditions
|
||
switch (actionType) { | ||
case 'addProperties': | ||
Object.assign(state, action.extraData); |
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.
you modified initial state, it's a bad idea
you need to create a clone of the state and modify this cloned object
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.
No description provided.