-
Notifications
You must be signed in to change notification settings - Fork 903
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 openSidebarSections in redux store #9381
Implement openSidebarSections in redux store #9381
Conversation
/** | ||
* Helper function: returns an array with the requested item removed. | ||
* | ||
* @param {Array} openSections The array from which the item should be removed. |
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.
Name doesn't match parameter openSidebarSections
* Helper function: returns an array with the requested item removed. | ||
* | ||
* @param {Array} openSections The array from which the item should be removed. | ||
* @param {string} removeItem The item to be removed. |
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.
Name doesn't match parameter removeSection
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.
Also I think the name of the param should just be sectionId
. Same goes for sidebarSectionCloser
.
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.
Wasn't sure we would use ids, names, indexes, etc.
So I called it item. I'd rather change the action's fields to address your concerns.
* | ||
* @returns {Array} The array without the item that should be removed. | ||
*/ | ||
let sidebarSectionCloser = ( openSidebarSections, removeSection ) => { |
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.
Should be const
return openSidebarSections.filter( item => item !== removeSection ); | ||
}; | ||
|
||
let sidebarSectionOpener = ( openSidebarSections, addSection ) => { |
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.
Should be const
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.
Doesn't have documentation
@@ -0,0 +1,49 @@ | |||
import { CLOSE_ALL_SIDEBAR_SECTIONS, OPEN_SIDEBAR_SECTION, CLOSE_SIDEBAR_SECTION } from "../actions/openSidebarSections"; |
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.
If you write functions to handle state change I think it's better to name them after the action instead of their responsibility. So I think sidebarSectionOpener
should just be openSidebarSection
for example.
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.
I agree, but for readability's sake I used sidebarSectionOpener()
because of overlap with the redux action OPEN_SIDEBAR_SECTION
and its creator openSidebarSection()
.
Will consider changing.
]; | ||
}; | ||
|
||
/** |
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 make it more elaborate than it needs to be ;)
/**
* A reducer that manages the open state for sections.
*
* @param {string} state The current state of the object.
* @param {Object} action The current action received.
*
* @returns {string} The state.
*/
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.
While I agree I went a little overboard here, what I was going for was documenting which part of the state this reducer actually manages. In this file you cannot see this anywhere, you'd have to visit the rootReducer in edit.js. To have everything together, it could be worthwhile to write down the name of the state that is managed per reducer.
Just saying I disagree with the usage of an array in this case. |
I did too, initially, but @atimmer convinced me. I think for now an array solves the issue adequately. |
CR 👍 |
Acceptance 👍 |
…ns-redux Revert "Merge pull request #9381 from Yoast/stories/9305-2-implement-openSections"
Summary
This PR can be summarized in the following changelog entry:
Relevant technical choices:
Test instructions
This PR can be tested by following these steps:
Quality assurance
Fixes #9305