Conversation
|
@leeyi45 could I ask for your thoughts/preliminary comments on this proof-of-concept refactoring? If it's all good, I'll proceed to refactor the rest of the reducer. Thanks! |
Pull Request Test Coverage Report for Build 8678817523Details
💛 - Coveralls |
| return createReducer(defaultSideContentManager, builder => { | ||
| builder | ||
| .addCase(changeSideContentHeight, (state, action) => { | ||
| state.stories[storyEnv].height = action.payload.height; |
There was a problem hiding this comment.
Note that sideContentState above is outside the createReducer function; thus it is not a "writeable draft" state from Immer and should not be written to, i.e. sideContentState.XXX = YYY is not allowed.
|
Should we call |
How can we capture |
Do we need to capture |
That's true, I had originally thought that it might be not very ideal to have to write a const workspaceLocation = // ...
const sideContentState = // ...every time. But now that I think of it, the duplicated But I still feel that the reducer should be split between stories and non-story workspace locations. What do you think of something like: export const SideContentReducer = (state, action) => {
state = storiesSideContentReducer(state, action);
state = nonStoriesSideContentReducer(state, action);
return state;
};
const storiesSideContentReducer = createReducer(
defaultSideContent,
builder => {
builder.addCase(someAction, (state, action) => {
if (action.payload.workspaceLocation === 'stories') {
// ... logic here
}
});
}
);
const nonStoriesSideContentReducer = createReducer(
defaultSideContent,
builder => {
builder.addCase(someAction, (state, action) => {
if (action.payload.workspaceLocation !== 'stories') {
// ... logic here
}
});
}
);That way we group all the logic for non-story and stories together. Though ideally, we remove the duplication entirely since the only differences would be how we access |
I guess if we want to maintain the difference between story and non-story side content we could do that What I had in mind was more like: export const SideContentReducer = (state, action) => {
const [workspaceLocation, storyEnv] = getLocation(action.payload.workspaceLocation)
if (workspaceLocation === 'stories') {
const workspace = state.stories[storyEnv]
return {
...state,
stories: {
...state.stories,
[storyEnv]: reducer(workspace)
}
}
}
// and the same for non-story workspace locations
}The whole idea is to treat each workspace identically. But I guess that's less idiomatic? |
…nto refactor-side-content-reducer
Description
Refactors
SideContentReducerto use "RTK" and Immer, as well as splitting the logic of stories and non-stories side content into separate sub-reducers for better readability.Type of change
How to test
Checklist